SAP HANA Local Native Development: Unterschied zwischen den Versionen

Aus MattWiki
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 65: Zeile 65:


  hana-cli tables
  hana-cli tables
== Create Local Runtime Environment with default-env.json ==
The ''default-env.json'' enables you to run CF environments on your development machine or in the SAP BTP without deploying applications to the CF.
<syntaxhighlight lang="json">
cds{
  "SERVICE_REPLACEMENTS": [
    {
      "key": "ServiceName_1",
      "service": "CROSS_SCHEMA_SFLIGHT"
    },
    {
      "key": "hdi-user-service",
      "service": "hana-opensap-cloud-2020-user-db"
    }
  ],
  "VCAP_SERVICES": {
    "xsuaa": [
      {
        "name": "bookshop-uaa",
        "label": "xsuaa",
        "tags": [
          "xsuaa"
        ],
        "credentials": {
            ...
        }
      }
    ],
    "hana": [
      {
        "name": "hana-opensap-cloud-2020-db",
        "tags": [
          "hana"
        ],
        "credentials": {
          ...
        }
      }
    ]
  }
}
</syntaxhighlight>
=== Add Database Connection to default-env.json ==
hana-cli serviceKey hana-opensap-cloud-2020-db default
hana-cli status
hana-cli systemInfo
=== Add Authentication to default-env.json ===
See https://cap.cloud.sap/docs/node.js/authentication
=== Add Service Replacements to default-env.json ===
Add section SERVICE_REPLACEMENTS (see above)


[[Category:SAP]]
[[Category:SAP]]
[[Category:HANA]]
[[Category:HANA]]

Version vom 14. Juni 2021, 15:55 Uhr

This article describes how to develop HANA native database modules locally without Web IDE and even without XSA server.

For CAP development with CLI see SAP HANA CAP Development

The approach described below deploys the data to a local SAP HANA Express but it could be deployed to Cloud Foundry as well.

hana-cli is a tool from SAP development which contains some scripts which reproduce the behavior of the Web IDE when building and deploying apps. Without the Web IDE one could use CF / XS to create the appropriate services, which are built tand deployed by the Web IDE. But if one wants to work even without CF / XSA server all of the tasks need to be done with the appropriate NPM tools. In order to make this easier hana-cli comes into play.

Source: ABAP Freak Show Ep. 6 - HANA; Local Development, VCAP_SERVICES, and HDI Deployer Tips and Tricks

https://www.youtube.com/watch?v=JLfv04rlmfI&list=PLoc6uc3ML1JR38-V46qhmGIKG07nXwO6X&index=67

Installation of Prerequisites

Relevant Tools from SAP

npm i -g @sap/cds
npm i -g @sap/cds-dk

Additional 3rd Party Tools1

npm i -g hana-cli

Setup Project

Create a new folder for the project.

Create a DB module inside the project:

hana-cli createModule

Connect to HANA DB - if asked for user don't forget to enter a HANA user, not a XSA user:

hana-cli connect

Get different infos of connected server:

hana-cli systemInfo -a
hana-cli status -a
hana-cli schemas -a

Create HDI Container

hana-cli createContainer

This actually uses SQL statements to create the HDI container to execute the same processes as the build function in the Web IDE would do. When asked for a container name remember to use a unique name. The Web IDE by default adds a _1 at the end of the name of the HDB module.

The createContainer statement needs to be issued from the db folder of the project. Also a default-env-admin.json file is needed in the db folder as well. This creates a default-env.json file which contains the connection details. Now the following statement without the -a is available (which stands for admin):

hana-cli status

This shows the current user, which should be the runtime user and also its roles in the HANA db.

Build and Deploy Project

First let NPM download the necessary libraries that the project depends on. i.e. @sap/hdi-deploy, which are defined in package.json

npm install -global

Now start the deploy process defined in the package.json by issuing:

npm start

Check crated tables:

hana-cli tables

Create Local Runtime Environment with default-env.json

The default-env.json enables you to run CF environments on your development machine or in the SAP BTP without deploying applications to the CF.

cds{
  "SERVICE_REPLACEMENTS": [
    {
      "key": "ServiceName_1",
      "service": "CROSS_SCHEMA_SFLIGHT"
    },
    {
      "key": "hdi-user-service",
      "service": "hana-opensap-cloud-2020-user-db"
    }
  ],
  "VCAP_SERVICES": {
    "xsuaa": [
      {
        "name": "bookshop-uaa",
        "label": "xsuaa",
        "tags": [
          "xsuaa"
        ],
        "credentials": {
            ...
        }
      }
    ],
    "hana": [
      {
        "name": "hana-opensap-cloud-2020-db",
        "tags": [
          "hana"
        ],
        "credentials": {
          ...
        }
      }
    ]
  }
}

= Add Database Connection to default-env.json

hana-cli serviceKey hana-opensap-cloud-2020-db default hana-cli status hana-cli systemInfo

Add Authentication to default-env.json

See https://cap.cloud.sap/docs/node.js/authentication

Add Service Replacements to default-env.json

Add section SERVICE_REPLACEMENTS (see above)