SAP BTP CAPM Application Development and Deployment โ€“ Part 4

1 month ago 16

BTP CAPM Part 4

Welcome to Part 4 of our SAP BTP Application Development series! ๐Ÿ‘‹
In the previous parts, we explored how to set up our environment in SAP Business Application Studio (BAS), understand the project structure, and prepare for multi-target applications (MTAs) deployment.
In this article, weโ€™ll take our learning a step further by developing a basic CAPM (Cloud Application Programming Model) application and integrating it with SAP HANA Cloud Database. This hands-on guide will walk you through the key steps โ€” from creating the project structure to deploying it to the SAP BTP environment.

Perquisites:

  1. You have a BTP Trial account created.
  2. You have subscribed to SAP Business Application Studio.
  3. You have subscribed to the SAP HANA Cloud and created an instance.
  4. Your HANA Cloud DB instance must be in running condition.

Before we proceed with our tutorial, we would like to give you an opportunity to join ourย ZAPYardโ€™s learning communityย where we have more than 35 groups and more thanย 1850 real SAP Consultantsย interacting with each other daily.ย Only SAP topics and not BS. Else, they will be banned from the community without warning. ๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡

If you want to be part ofย ZAPYardโ€™s Discussion Community, please feel free to check the below Link.ย We Ask, Answer, Help and Learn Together.ย There are more than 35 groups from different topics likeย Generative AI, SAP Joule, CAPM, BTP, RAP, BPT, Fiori, iRPA, CAI, CPI, PI/PO, ABAP on HANA, SAPUI5, SAP Build, SAP Adobe Forms, ChatBots, SACย etc. Join any group of your interest and interact with our Community.

Join ZAPYardโ€™s WhatsApp Community โ€“ Ask, Answer, Propose & Defend SAP Topics

Step 1: Create a new CAPM project from template

1. Return to the Explorer view. From the SAP Business Application Studio Welcome tab, click New Project from Template.

2. Choose CAP Project and click Start

3. Use the following name for your project and click Next

This name will be used in different steps. It is recommended that you do not change it unless you remember to replace it in future tasks.

Choose Node.js as the runtime. Select SAP HANA Cloud from the database for your application section. Choose Cloud Foundry:MTA Deployment and CI/CD Pipeline Integration under which way to deploy your project. Choose SAP BTP Authorization and Trust Management Service (XSUAA) and SAP Application Router from the productive runtime capabilities for your application section. Press Finish

The new project should be added to your workspace automatically.

Step 2: Install dependencies We are using several dependent Node.js modules in our project.

They are referenced in the dependencies section of the package.json file we were just editing. These dependencies need to be installed into your project before we can do any testing.

1. Open a new terminal

2. The terminal will open in the bottom right of the Business Application Studio

3. From the terminal run the command npm install

4. We will use an open source sample utility called hana-cli to help with development tasks. From this same terminal window run the command npm install -g hana-cli in order to install it for later usage.
npm install -g hana-cli

Step 3: Creating Database Entities for CAPM

Letโ€™s start with the DB Folder: It contains the Database Entity which is based on CDS Model. The design-time artefacts declared in this file will be converted to run-time, physical artefacts in the database. In this example, the entities will become tables.
Right Click on db folder & create a New File.

Name the file as data-model.cds

Now, letโ€™s create an entity, you can copy the below code and paste it into the created file.

Step 4: Creating a Service for CAPM using the Data-Model

Now go to the srv folder. We will be declaring services to expose the database entities we declared in the previous step.
Create a new file in srv folder by right-clicking on the same.

Name the file as cat-service.cds

Copy & Paste the below code in the created file.

Step 5: Connect to the HANA Cloud Instance & deploy the app
You will now deploy those objects into the HANA Database creating tables and views. We will use the SAP HANA Projects view to do this. Please expand this view and you will see the following:

1. We need to bind our project to a Database Connection and HDI container instance. Press the bind icon to being the process.

2. If you receive either of these two following warning dialogs, please just choose Continue (nothing will be deleted because we are creating a new HDI Container Instance) and Enable (automatic undeployed is quite helpful during the development process for the reasons described in this dialog)

3. The bind process will start a wizard where you will be prompted for values via the command pallet at the top of the SAP Business Application Studio screen. You might be asked to confirm your Cloud Foundry endpoint and credentials depending upon how long it has been since you last login.

4. Your first choice will be for the binding option. Choose Bind to an HDI container.

You might be presented with options for existing service instances (if youโ€™ve completed other tutorials or have performed other HANA development). But for this exercise we want to choose Create a new service instance

6. To make subsequent steps easier, shorten the generated name to MyHANAApp-dev + a group number or your initials if you are doing this tutorial as part of a group workshop/shared environment. This makes sure that everything remains unique per participant. Remember the value you used here and adjust the name in the subsequent steps. The remaining screenshots will always just show the base name.

7. It will take a minute or two for the service to be created in HANA. A progress bar will be shown in the message dialog

8. Sometimes the binding step fails due to a timing issue. If so simply repeat the binding but this time do not create a new container name but select the existing HDI container that has been created from the previous attempt MyHANAApp-dev

9. Upon completion, the Database Connections will now show the service bound to the instance the wizard just created.

10. We are now ready to deploy the development content into the database. Before you go ahead, we recommend that you increase the default number of scrollback lines in the integrated terminal, if youโ€™re using a Dev Space in SAP Business Application Studio. This is because there are many lines of log output about to be generated and you will want to see them all. So use menu path File -> Preferences -> Settings and search for the โ€œTerminal โ€บ Integrated: Scrollbackโ€ setting. Set the value to 10000. Now, once youโ€™ve done that, youโ€™re ready to deploy. Press the Deploy button (which looks like a rocket) at the db folder level in the SAP HANA Projects view.

Click the below icon to open the HANA Database Explorer

Go to the tables, you can find the table

You can find the tables in the SAP HANA Database Explorer.

You can right click on the table and import Data.

You can have a .csv file with some sample data to import.

Step 6: Check data loaded into the tables

1. We can use this same configuration information from Cloud Foundry to start the CAP service layer and connect it to SAP HANA as well. Use the command cds bind -2 MyHANAApp-dev-00:SharedDevKey to tell CAP to bind to this same HANA Cloud HDI service instance that we bound to earlier in the SAP HANA Projects view.

2. Run the command npm install to install any Node.js dependent modules needed by the Cloud Application Programming Model.

3. Our project is setup for real XSUAA security and we will use that later in this tutorial. But for now we want to test without configuration of the necessary authentication and authorization setup. To do so, open the package.json file in the root of your project. Change the cds.requires.auth property from xsuaa to mocked so we can test with mock authentication.

4. Now issue the command cds watch โ€“profile hybrid. This will start the CAP service locally and use the binding configuration to connect to our remote HANA database instance. Once started you will see a dialog with a button that says Open in New Tab. Press this button to test the CAP service in a new browser tab.

If you accidentally close this dialog, you can always open the running services via View > Command Pallette and then choosing Ports: Preview and choosing the running service from the list

Click on SalesOrder

If you found this article helpful, weโ€™d love to hear from you! Share your thoughts, questions, or experiences in the comments belowโ€”your feedback is always welcome and helps us craft even more valuable content for your ABAP on Cloud journey. Stay tuned for the next part in the series, where weโ€™ll continue exploring essential tools and techniques to level up your SAP development skills.

Please note: This CAPM Series is the learning material from ourย ZAPcademy.comย Instructor Led Live Online Training on the topicย SAP BTP CAPM โ€“ Basic to Advanced. You may avail the recordings, notes and assignments of this training fromย here.

Please follow ourย LinkedIn Page,ย LinkedIn Groupย ,ย Facebook Page,ย Facebook Group,ย Twitterย &ย Instagram.

Do not forget toย SUBSCRIBEย to ourย YouTube Channelย for Free Courses and Unconventional Interesting Videos.

Do join ZAPYardโ€™s Learning Community.

Read Entire Article