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