Goal :
This Blog explains how you can leverage native SAP HANA development artifacts with CAP. In particular we look at the use of Calculation Views, inside Cloud Application Programming (CAP) Applications. This includes OData access to Calculation Views.
Solution:
Pre-requisites: Set Up SAP Business Application Studio for Development
NOE: In the SAP BTP trial and free tier you are limited to only two Dev Spaces and only one can be active at a time. If you have performed other tutorials, you might already have reached your maximum. In that case you might have to delete one of the other dev spaces in order to continue with this tutorial.
Selection of the type - Full Stack Application in Business Application Studio
It will then create a dev space. Although it takes couple of minutes to start. Once it is RUNNING, you can click on CAP_DEMO and start creating your projects.
Newly created DEV space in BAS
Login to Cloud Foundry, there are several ways to login to cloud foundry
Cloud Foundry Login in BAS
Fill in the credentials & necessary details such as Cloud Foundry Organization & Cloud Foundry Space.
Enter Credentials and Dev Space details
2. Using the Artifact Wizard by clicking on F1.
Cloud Foundry login using Artifact Wizard (F1)
3. Using the terminal: Execute the command,
CF LOGIN
Terminal - CF LOGIN
Choose from the template ( CAP Project )
Set your runtime as node.js and add the features that’s selected in the image below and click on finish.
It will then create a CAP Project with some sample folders and files.
Project Explorer
CDS ADD HANA
mta.yaml file
Now change the path from gen/db -> db
Change the path in mta.yaml
Now, change the cds section of the package.json to the below block of code.
Changes in the file package.json
Before & After the addition of CDS Section in package.json
Open the terminal and execute
Install the dependencies
(OPTIONAL) You can clone your git repository or continue with the project with next steps.
Initialize the Git Repository
data-model.cds
2. srv > cat-service.cds
cat-service.cds
Run the following command
cds build
cds build
CDS artifacts are now converted to hdbview and hdbtable artifacts and you can find them in the src folder.
CDS Artifacts in the Explorer
Deploy these objects into HANA database creating tables and views. Bind the project to a database connection and HDI container instance. Click on the bind icon.
The connections with respect to CAP & HANA tooling are distinct. They do not share the same connection. Hence, binding must be done at 2 different points : (a) SAP HANA Project (b) Run Configurations.
(a) Binding the HANA Project
Select an SAP HANA Service and choose from the list displayed.
SAP HANA Service
Go to the plugin Run Configuration and bind the connection.
(b) Binding in Run Configuration
Select 'Yes' to the below dialog box.
Once deployed, go to Run Configurations, and click on the run button. This will give an another dialog box to open 'Bookshop-1' a new tab.
Run the CAP Project
Application running at port 4004
If you click on the $metadata, you can view the technical description of the service.
$metadata
Click on Fiori Preview, attributes have to be selected by clicking on the gear icon ⚙️.
Fiori Preview
Create a calculation view, click on F1 which in turn will open a wizard to create the database artifact.
Database Artifact Wizard - Create Calculation View
In the Calculation View Editor, Click on the + icon on the projection and add the table. On the right side, there is an icon to expand the details of the projection. By clicking on it, it opens the panel and here you can map the table attributes, by double clicking on the MY_BOOKSHOP_BOOKS header.
Calculation View Editor
Once deployed, you can view the Calculation View in the Database explorer.
Database Explorer
data-model.cds
cat-service.cds
Create. hdbsynonym in your src folder
Database Artifact Wizard - Create Synonym
Click on <click_to_add> and enter the synonym name, MY_BOOKSHOP_CV_BOOK and click on the object field, the below table opens. Enter ** on the text field and choose the calculation view cv_book and click finish.
If you open the cap.hdbsynonym in the text editor, it will be as follows.
Synonym - cap.synonym
Deploy the project by executing the command cds deploy -2 hana. You can refresh the browser. You can find the new cv_book entity.
Application with new entity
Conclusion: With some settings inside the development environment, it is possible to combine the use of HANA Native artifacts like Calculation Views with HDI generated code artifacts of CAP to build applications.
Following are some of the quick links:
SAP HANA Cloud Overview
About CAP
SAP HANA Deployment Infrastructure
Follow this tutorial : Combine CAP with SAP HANA Cloud to Create Full-Stack Applications
Please share your valuable feedback.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
17 | |
14 | |
12 | |
10 | |
9 | |
8 | |
7 | |
7 | |
6 | |
6 |