Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
rahul_rajagopal
Explorer
Till now, we have discussed in detail to set up the infrastructure/tools/services to start our CAPM development(Access the previous modules).

Let's start with building our First application. Follow the below steps to open your business application studio.

  • Log on to BTP trial cockpit

  • Click on "Go To Your Trial Home"

  • Click on the subaccount, "trial"

  • Click on the  "Services" option in the left hand panel and further click on "Instances and Subscriptions"

  • Under the "Subscription", you can now see the SAP Business Application Studio. Click the link to open the same. Business application studio will now open in another tab of your browser.

  • You will be Signed using SSO and would be able to view the below screen





  • Click on "Create Dev Space" as shown in the above image.

  • In the next screen, you can choose the dev space application type depends on your needs. Those who are already working in SAP Fiori/UI5 application development  might familiar with this. My personal choice is to use "SAP HANA Native Application" option for CAPM development at this moment. As the applications we create using CAP model will be a MTA(Multi Target Application), we can ideally have 2 different dev space. One is for HANA Native application development where we build CDS view and Service. The other is for Fiori/UI5 application development. However, there is no restriction to use "Full Stack Cloud Application" option. The reason to propose to have two different dev space is because; most of the developers may not be a full stack developers. Which means front end developer can developer the UI5 application and backend team can build the HANA artifacts parallelly and later they can be integrated.

  • Here i am using the dev space name as "HANA_NAT_DEV".

  • Choose the Additional SAP Extensions if required. Here I am choosing all from the list as shown below.





  • Now click on "Create Dev Space" and wait until the dev space status turns to "Running" as shown below.





  • Click on the "HANA_NAT_DEV" to open your IDE, which is nothing but the Business Application Studio.


You are now ready with your business application studio set up.

We will now start our application development. A CAPM application can be created either using the template wizard or using the command line. As we are just started our learning, let's start with the command line.

Create CAPM Application



  • As a first step, open your workspace. Follow the below Path.

  • Click on the three line button -> File -> Add Folder to Workspace. This will open command pallet. As a practice, all your projects must come under the folder /home/user/projects



 




  • Click on "OK" button will add the folder under your workspace.

  • Right click on the project folder and choose "Open in Integrated Terminal". A command line will now open for your input as shown below





  • Use the command "cds init" followed by your application name to create your first CAPM application. You may have to understand that the complete design of CAPM application is based on CDS.

  • Once you press enter after the command "cds init EmployeeData", the whole application structure will be created in the left hand side with all the necessary files as shown below.





  • For a CAP application, there are 3 important folders. We will discuss about in the below section in detail

    • app - UI content. We will discuss in detail later when we consume the service in UI5 application.

    • db - Domain models and database-related content

    • srv - Service definitions with implementation

    • Let's now create a a new file under "db" folder with name "data-model.cds". Here the file name not really matters, you can provide any name. But make sure you are providing the extension ".cds".

    • Add the below code in the file.




namespace btp.emp;

entity EMPLOYEE {
key ID : String(15);
NAME : String(255);
EMIL_ID : String(128);
DEPARTMENT : String(50)
}




    • Let's now create a new file under "srv" folder with name "Employee-service.cds". Here also, file name can be anything. Make sure the extension is ".cds".

    • Add the below code in the file




using btp.emp as emp from '../db/data-model';

service EmployeeService {
entity Employee as select from emp.EMPLOYEE;
}




    • Always use "cds watch" to see the error if any. Once you run "cds watch", if there is no error, you will get a pop up as shown below.









    • Click on the "Open in a New Tab" to view the metadata of the service just now you have created. See the image below.









    • Click on the "$metadata" to view the metadata structure of the service you just created.









    • This is still a local url. We can't access this outside of Business Application Studio.

    • To deploy the application, we need to add one more dependency called "cds".

    • Add the below code in "package.json" file




  "cds": {
"requires": {
"db": {
"kind": "hana"
}
}




    • Now we need to make BAS to create all the dependency automatically. Use the command "npm indtall" to do the same.

    • After successful execution, you can now see, BAS has inserted another folder "node_modules" which consist of all the dependent components as shown below.









    • In order to deploy, we need to connect our "Shared SAP HANA" instance with our application. Go to the "Run configuration" and hit "Create Configuration". If you can't find the "Run Configuration", click on the three dots as shown below.






 



    • Select the necessary value from the drop down as shown below.









    • A run configuration is now created.

    • Now click on the bind icon as shown below









    • Now you need to input your "Cloud Foundry Endpoint" url and authentication details as shown below. The url can be copied from the BTP cockpit.





 






    • Click on "Sign In"

    • Select the space and click "Apply" as shown below









    • You can select the "HDI Container" from the dropdown to deploy.

    • Once you select the "HDI Container", BAS will ask confirmation to deploy the application as shown below. Upon confirmation, artifacts will be deployed.









    • You can view the Realtime log in the  BAS. Once you have seen the success response, you can check the SAP HANA environment to view the database artifacts such as table and view. Make sure that your SAP HANA instance is in running status before performing the Bind activity.

    • Also you can now see another folder "gen" is got created in the project hierarchy.

    • Run command "npm install" again to add all the dependent libraries and components.

    • Add your "mta.yaml" file using the command "cds add mta".

    • We can now build the "mta.yaml" file to deploy the application.

    • Right click on the "mta.yaml" file and choose the option "Build MTA project"

    • Any time before deployment you can delete and recreate the "mta.yaml" file using "cds add mta" command.

    • Once you are done with MTA build, you can now see a new folder "mta_archives". It is now time to deploy the MTA archive.

    • To deploy, first use the command "cf login" to log on to the cloud foundry environment.

    • Follow the instructions from the screen as mentioned in the below.










    • Now right click on the MTA Archive file and click "Deploy MTA Archive"

      • After the deployment, if you face some error, use the command "cf logs EmployeeData-srv --recent" to retrieve the log from cloud foundry environment. Here "EmployeeData-srv" is my application name. You have to change it with your application name.

      • In my case, i have few errors reported stating that some modules are missing. I have installed it using command "npm i passport" , "npm install -g npm@9.8.1" and "npm i @Sap/xssec"

      • Now attempt to deploy again by right click on the MTA Archive file and click "Deploy MTA Archive"



    • Once the deployment is success, you may get a success confirmation in the command line.

    • You can cross check by log on to your "dev space" under your trial account as shown below









    • Moreover, To view deployed HANA table/views, use the command "SAP HANA: Open Database explorer" in the "Command palette". Below is the sample view.





 

Conclusion


You are now ready to create simple CAPM application and able to deploy database and services to SAP HANA cloud and Cloud Foundry Environment.

Also, please follow the topic page, post and answer questions and read other posts on the topic
3 Comments
Labels in this area