In this blog post, I will show you how to add native HDB artifacts using SAP HANA tools to SAP Cloud Application Programming Model projects. We will start by creating an SAP Cloud Application Programming Model project, and then we will adjust it step-by-step to work with SAP HANA tools. We continue to improve our tools so that in the near future, there will be no need for these manual steps.
STEP 1: Add SAP HANA Tools Extensions to SAP Cloud Business Application Dev Space
The first step is to create an SAP Cloud Business Application dev space and add the following additional SAP extensions to it:
◉ SAP HANA Tools – Allows you to develop native SAP HANA applications. The extension includes tools such as graphical and text-based editors, project generators, etc.
◉ SAP HANA Database Explorer – Allows you to access and inspect SAP HANA run-time objects using SAP HANA Database Explorer.
◉ SAP HANA Calculation View Editor – Allows you to edit and manage SAP HANA calculation views. The extension includes the SAP HANA calculation view editor, the synonym editor, and the analytical privilege editor.
If you already have your own dev space, you can always edit it and add to it additional extensions by clicking the Edit icon in the Dev Space Manager.
STEP 2: Create an SAP Cloud Application Programming Model Project
SAP HANA Tools supports only MTA projects.
When creating a new SAP Cloud Application Programming Model Project using “Create Project from Template” from the command palette, select the following features:
◉ Configuration for SAP HANA Deployment
◉ MTA based SAP Cloud Platform Deployment
If you already have your own SAP Cloud Application Programming Model project, you can add an MTA file using the following command in the terminal, under the project root:
cds add mta
STEP 3: Define the HDB Module Path
In Node.js projects, by default, the HDB module path in the “mta.yaml” file points to the “gen/db” folder.
We need to edit the “mta.yaml” file so that it points to the “db” folder.
STEP 4: Define the CDS Build Output Directory
The SAP HANA PROJECTS view allows you to deploy to the database HDB artifacts that reside under the DB module. To deploy also data models that were defined using CDS, you need to change the CDS build output folder. It should be generated under the DB module.
In Java projects, by default, the target folder is defined under the DB module.
In Node.js projects, set the CDS output directory by adding the following definition to the “package.json” file:
"cds": {
"build": {
"target": "."
}
}
In addition, in the “package.json” file, change the “kind” property to “hana”, to create a run configuration that uses HANA as the target database instead of SQLite.
"requires": {
"db": {
"kind": "hana"
}
}
STEP 5: Working with SAP HANA CLOUD
SAP HANA Cloud does not support hdbcds.
If you deploy your HDB artifacts to SAP HANA Cloud, configure the CDS build command to generate hdbtable and hdbview artifacts instead of hdbcds.
In the Node.js project, add the following in your “package.json” file:
"hana": {
"deploy-format": "hdbtable"
}
The resulting “package.json” file should look like this:
In a Java project, add the configuration to the project’s “.cdsrc” file.
"hana": {
"deploy-format": "hdbtable"
}
STEP 6: Define the HDB module’s “package.json” file
In a Node.js project, add a new “package.json” file under the DB folder with the following content:
{
"name": "deploy",
"dependencies": {
"@sap/hdi-deploy": "^3"
},
"scripts": {
"start": "node node_modules/@sap/hdi-deploy/deploy.js"
}
}
STEP 7: Add an HDB artifact to your data model
You can now add your native HDB artifacts under the “db\src” folder using the SAP HANA: Create SAP HANA Database Artifacts command in the command palette.
STEP 8: Deploy your HDB Artifacts to the database
To deploy your HDB artifacts to the database:
1. From the terminal, run the following command under the project root to convert the CDS definition to HDB format.
cds build --production
Make sure that a “gen” folder was generated under the “db/src” folder and that all of your HDB artifacts were generated correctly under the “gen” folder.
2. In the SAP HANA PROJECTS view, under Database Connections, bind your resource to a new or an existing HDI Container service instance.
3. In the SAP HANA PROJECTS view, click the Deploy icon to deploy your HDB module.
4. If you want to expose your native HDB artifacts as an OData service, you can use the SAP HANA CLI tool to create its CDS proxy entity.
STEP 9: Run your project
To locally test your project, use the Run Configurations tool.
In a Node.js project:
1. Add a run configuration to your project.
2. Bind your service to the same HDI Container service that you used in the SAP HANA PROJECTS view.
In a Java project:
1. Generate the “default-env.json” file using the following command:
cds deploy --to hana:myService --auto-undeploy
Make sure to use the same HDI Container service name as in the SAP HANA PROJECTS view.
2. Add a cloud profile.
In the “application.yaml” file under “srv\src\main\resources\”, add an empty cloud profile:
---
spring:
profiles: cloud
3. Add a new run configuration using the cloud profile.
No comments:
Post a Comment