5

SAP HANA Development with SAP Cloud Application Programming Model using SAP Busi...

 1 year ago
source link: https://blogs.sap.com/2022/11/30/sap-hana-development-with-sap-cloud-application-programming-model-using-sap-business-application-studio/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

SAP HANA Development with SAP Cloud Application Programming Model using SAP Business Application Studio

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

  • Launch the Business Application Studio (BAS) and choose Create Dev Space

Note: NOTE: 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.

  •  Select the Full stack application and select the necessary extensions as shown in the image below and click on the create dev space.
Picture1-70.png

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.

Picture2-52.png

Newly created DEV space in BAS

  • Add Cloud Foundry LOGIN Connection to your space ( 1.Plugin 2. F1- 3. CF )

Login to Cloud Foundry, there are several ways to login to cloud foundry

  1. In the plugins, go to cloud foundry icon and click on the right arrow as shown in the picture.

    

Cloud%20Foundry%20Login%20in%20BAS

Cloud Foundry Login in BAS

Fill in the credentials & necessary details such as Cloud Foundry Organization & Cloud Foundry Space.

Enter%20Credentials%20and%20Dev%20Space%20details

Enter Credentials and Dev Space details

2. Using the Artifact Wizard by clicking on F1.

Cloud%20Foundry%20login%20using%20Artifact%20Wizard%20%28F1%29

Cloud Foundry login using Artifact Wizard (F1)

3. Using the terminal: Execute the command,

 CF LOGIN

Picture6-27.png

Terminal – CF LOGIN

  • Create CAP Project : Once you have logged in to Cloud Foundry,  Start with the creation of CAP Project by clicking on the Start from Template  ( Help > Get Started > Start from Template) and click on CAP Project.
Choose%20from%20the%20template

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.

Picture8-13.png

It will then create a CAP Project with some sample folders and files.

Project%20Explorer

Project Explorer

  • Adding HANA Target to the Project : Open new terminal (Terminal > New Terminal) and execute the command

    CDS ADD HANA

    Terminal%20%3A%20CDS%20ADD%20HANA
    You can see the dependencies in the mta.yaml file.
mta.yaml%20file

mta.yaml file

  • Adjust the content in the files mta.yaml & package.json

Now change the path from gen/db -> db

Picture12-10.png

Change the path in mta.yaml

Now, change the cds section of the package.json to the below block of code.

Picture13-8.png

Changes in the file package.json

Picture14-8.png

Before & After the addition of CDS Section in package.json

  • Install the dependencies

Open the terminal and execute

  • npm install ( NOTE: Skip the step if already installed )
  • npm install -g hana-cli (Open Source Utility called hana-cli )
  • hana-cli createModule
Install%20the%20dependencies

Install the dependencies

(OPTIONAL) You can clone your git repository or continue with the project with next steps.

Initialize%20the%20Git%20Repository

Initialize the Git Repository

  • View the files added from the CAP template
  1.  src > data-model.cds
data-model.cds

data-model.cds

       2. srv  > cat-service.cds

cat-service.cds

cat-service.cds

Run the following command

cds build

Picture19-7.png

cds build

CDS artifacts are now converted to hdbview and hdbtable artifacts and you can find them in the src folder.

CDS%20Artifacts%20in%20the%20Explorer

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.

Binding%20the%20HANA%20Project

(a) Binding the HANA Project

  • Create Service Instance

Select an SAP HANA Service and choose from the list displayed.

SAP%20HANA%20Service

SAP HANA Service

Go to the plugin Run Configuration and bind the connection.

%28b%29%20Binding%20in%20Run%20Configuration

(b) Binding in Run Configuration

Select ‘Yes’ to the below dialog box.

Picture25-3.png
  • Run the CAP Project

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%20the%20CAP%20Project

Run the CAP Project

Picture28-4.png

Application running at port 4004

If you click on the $metadata, you can view the technical description of the service.

Picture29-3.png

$metadata

Click on Fiori Preview, attributes have to be selected by clicking on the gear icon ⚙️.

Fiori%20Preview

Fiori Preview

  • Create Calculation View 

Create a calculation view, click on F1 which in turn will open a wizard to create the database artifact.

Picture32-2.png

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.

Picture33-3.png

Calculation View Editor

Once deployed, you can view the Calculation View in the Database explorer.

Database%20Explorer

Database Explorer

  • Edit the .cds files ( data-model.cds & cat-service.cds )
Picture31-3.png

data-model.cds

Picture35-3.png

cat-service.cds

  • Create Synonym

Create. hdbsynonym in your src folder

Picture36-2.png

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.

Picture37-1.png

If you open the cap.hdbsynonym in the text editor, it will be as follows.

Synonym%20-%20cap.synonym

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.

Picture39-4.png

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK