Skip to Content
Technical Articles

SAP Cloud Application Programming Model – Demo2

Hello All

This blog is continuation of my previous post: https://blogs.sap.com/2020/05/01/sap-cloud-application-programming-model-demo1/

Let’s discuss on the installation setup for SAP CAMP and an basic example of building SAP CAPM application using Node.js

Local Development tools required if we choose to develop the apps locally in our machine:

On cloud, SAP Business Application Studio is the IDE to develop SAP CAPM based applications.

SAP Business Application Studio features:

AS Core Data Service (CDS) is one of the foundation to our SAP CAPM developments, let’s see what does CDS refer to:

Core Data Service is a collection of domain-specific languages helping you during development to focus entirely on specific domain model.

Now i will be creating a basic SAP CAPM application using Node.js

Login to SAP Business Application Studio from Cloud Foundry space as seen in previous blog.

Create a new application in Projects folder by running the command cds init studentreport in the Terminal as shown.

Go to the directory studentreport by executing cd studentreport from Terminal.

user: projects $ cd studentreport

Create a data model in db folder: schema.cds

namespace sap.com.studentreport;

entity Student {
  key ID   : Integer;
  name    :  String(100);
  score :  String(20);
 attendance : String;
}

Execute cds watch from the Terminal to see the output.

user: studentreport $ cds watch

What does CDS watch will do for us: If there is a datamodel in the db folder, it will automatically be deployed to in-memory SQLite database.

Create a service file in SRV folder: cat-service.cds

using { sap.com.studentreport as my } from '../db/schema';
service CatalogService @(path:'/browse') {

  @readonly entity Student as SELECT from my.Student {*} ;
}

Again run CDS watch and observe the service output in new tab. We can see serving CatalogService at /browser and server listening which indicates the application is running

Let’s have some test data. Create a sub-folder data in db folder. Also create a file sap.com.studentreport-Student.csv with below info in data folder.

ID;name;score;attendance
1;Supriya Sidagam;87;80%
2;SuryaSainath Sidagam;81;85%
3;Bhuvana Sidagam;23;100%

Run the CDS watch and open the student service in new tab and see the above sample data in browser.

 

Let’s focus on business logic now. For that create a file cat-service.js in srv folder and write the below code.

module.exports = (srv)=>{

 const {Student} = cds.entities

srv.after ('READ','Student', (each)=>{
    if (each.score < 50) 
    each.name += ' -- You are failed'
  })
}

Project Structure:

Refresh the browser and check the output.

Please comment if any..

Thank you 🙂

#EnhanceLearning!!

BR//Dhanasupriya Sidagam

6 Comments
You must be Logged on to comment or reply to a post.
  • Really good explanation 🙂  Got a issue with Chrome browser. Little popup prompting at bottom when execute the cds watch command &  if you click on it, it should open another tab shown the $metadata of  entities. with chrome, its not opening another tab.

  • Hi Dhanasupriya,

     

    Thanks for tutorial. i am getting below error. can you please help.

    Node_modules is not not present in project – erorr @sap/cds/common’ is unknown.

    Below Error while running command npm start

    Node Modules location.

    /
  • Hi Dhanasupriya. Thanks for sharing. Please can you also share the production launch scenarios and how can we configure postman/http client to consume the cat service through the web?

    Regards, Diganto