In this 7 blog series, we are going to provide a small end-to-end scenario to work with SAP® CAPM. Here the usecase we are going to use is of Learning Management System(LMS) and build a Student List App and Deploy it to SCF.
Link to Master(or Main) Blog from which all the other blogs can be reached is Here.
If you wanted to check out the detailed course on SAP® CAPM the link is Here.
If you want to get learn SAP® Cloud Platform Development in Detailed then we have a 35hrs hands-on course Here.
For current offers and discounts check offer page Here.
Getting data in Fiori UI with annotations, just by using services.
Step 1: Missing Part
If we go inside by clicking on in Fiori link as shown below in the service output
We will get a Fiori based App with no data, as shown below
The issue here is that we have not added Annotation(s) in our data definition.
Annotations are required for UI to know how to bind the data to UI fields.
Step 2: Adding Annotations to Entities
We can add the UI Annotations to the CDS file present inside the db folder
Now if we restart the server with new code, we will see the Data in Fiori App, which previously we were not able to see with Fiori Preview.
This is how front page will look like
When we click on any Line item, we can navigate to detail page and also see the Header Info, as per our Annotation
Note: Here the Title which is email is not shown because the detail page(where we navigate) is not Object Page.
Before we end!
In this 7 blog series, we are going to provide a small end-to-end scenario to work with SAP® CAPM. Here the usecase we are going to use is of Learning Management System(LMS).
Link to Master(or Main) Blog from which all the other blogs can be reached is Here.
If you wanted to check out the detailed course on SAP® CAPM the link is Here.
If you want to get learn SAP® Cloud Platform Development in Detailed then we have a 35hrs hands-on course Here.
For current offers and discounts check offer page Here.
In this 7 blog series, we are going to provide a small end-to-end scenario to work with SAP® CAPM. Here the usecase we are going to use is of Learning Management System(LMS) and build a Student List App and Deploy it to SCF.
Link to Master(or Main) Blog from which all the other blogs can be reached is Here.
If you wanted to check out the detailed course on SAP® CAPM the link is Here.
If you want to get learn SAP® Cloud Platform Development in Detailed then we have a 35hrs hands-on course Here.
For current offers and discounts check offer page Here.
Steps for creating Schema, Database(Local with Sqlite3) and Service
Step 1: DB and CSV Folder
Add a folder named db in the project directory
mkdirdb
Inside db folder create another folder csv
mkdir csv
Step 2: Create the CDS Data Structure
Now we will create the data structure for our project, in this case we will create a simple Student entity
Create CDS
Create a .cds file where we are going to add the CDS structure
Here key is assigned as email and key is also a required field.
Step 3: Add CSV Data
Inside CSV folder create file using command
touchfilename.csv
Add data to the file as shown below, here we are adding data entries. The first row is coloum attribute followed by Data values of the respective Structure we created above.
Note: The filename should be same as the absolute path of the CDS entity, in this case this is myCompany.hr.lms-Students. So internally CAPM lib connects CSV Data to CDS entity.
Step 4: Create Service
In srv folder, we are going to create a projection without above cds structure. This will expose the CDS entity as Service.
Note: In this service, we have assigned an annotation on entity student which is @readonly. This annotation will restrict the entity to be read-only which means using the service entity records cannot be updated, deleted or inserted.
Also, here we have to be careful of the namespace, we have used the namespace myCompany.hr.lms so the service needs to use lms.Students to refer to our Student Entity in CDS view above.
using myCompany.hr.lms from'../db/<Your CDS Entity File Name>';
service first{
@readonly entity Students as projection on lms.Students;
}
Step 5: Installing Sqlite3 and Running
We can run locally with sqlite3 module, which will allow us to quickly test the result
So, let’s add sqlite3 in our project
npm i sqlite3
Now, lets run the CDS view, we are using --in-memory tag so that CDS will run using sqlite3 DB
cds run --in-memory
Also, if you want to deploy data to sqlite3 permanently then you can use
cds deploy --to sqlite
After running the deploy command, the output in console will be
> filling myCompany.hr.lms.Students from db/csv/myCompany.hr.lms-Students.csv
/> successfully deployed to ./sqlite.db
> updated ./package.json
And you will also see a sqlite.db file added to your project.
Now you can just use cds run next time to run app with data from sqlite DB. Also, you can use cds run --in-memory if in case, you changed some data/data structure(CDS) and want to quickly test in-memory.
Step 6: Final Result
We will have our application running in port 4004 by default, if we open http://localhost:4004 we will find our application running.
For seeing the data you can go to the URL: http://localhost:4004/first/Students
In this 7 blog series, we are going to provide a small end-to-end scenario to work with SAP® CAPM. Here the usecase we are going to use is of Learning Management System(LMS).
Link to Master(or Main) Blog from which all the other blogs can be reached is Here.
If you wanted to check out the detailed course on SAP® CAPM the link is Here.
If you want to get learn SAP® Cloud Platform Development in Detailed then we have a 35hrs hands-on course Here.
For current offers and discounts check offer page Here.
In this 7 blog series, we are going to provide a small end-to-end scenario to work with SAP® CAPM. Here the usecase we are going to use is of Learning Management System(LMS) and build a Student List App and Deploy it to SCF.
Link to Master(or Main) Blog from which all the other blogs can be reached is Here.
If you wanted to check out the detailed course on SAP® CAPM the link is Here.
If you want to get learn SAP® Cloud Platform Development in Detailed then we have a 35hrs hands-on course Here.
For current offers and discounts check offer page Here.
In this section we will be creating and running a simple CAPM Service, so lets start!
Step 1: Create a New CAPM Project
cds init <ProjectName>
This will create a Blank project of capm.
You will see 3 main content in the folder:
package.json
package-lock.json
node_modules
On going inside the node_modules folder you will see list of individual modules which got downloaded
root@apples-MacBook-Air:~/Desktop/Blog/capm1/demo1/demop/node_modules$ ls -l
total 0
drwxr-xr-x 3 root staff 102 Nov 21 15:20 @sap
drwxr-xr-x 7 root staff 238 Nov 21 15:20 accepts
drwxr-xr-x 6 root staff 204 Nov 21 15:20 array-flatten
drwxr-xr-x 8 root staff 272 Nov 21 15:20 body-parser
drwxr-xr-x 7 root staff 238 Nov 21 15:20 bytes
drwxr-xr-x 7 root staff 238 Nov 21 15:20 content-disposition
drwxr-xr-x 7 root staff 238 Nov 21 15:20 content-type
drwxr-xr-x 7 root staff 238 Nov 21 15:20 cookie
drwxr-xr-x 7 root staff 238 Nov 21 15:20 cookie-signature
drwxr-xr-x 15 root staff 510 Nov 21 15:20 debug
drwxr-xr-x 8 root staff 272 Nov 21 15:20 depd
drwxr-xr-x 6 root staff 204 Nov 21 15:20 destroy
drwxr-xr-x 6 root staff 204 Nov 21 15:20 ee-first
drwxr-xr-x 7 root staff 238 Nov 21 15:20 encodeurl
drwxr-xr-x 6 root staff 204 Nov 21 15:20 escape-html
drwxr-xr-x 7 root staff 238 Nov 21 15:20 etag
drwxr-xr-x 8 root staff 272 Nov 21 15:20 express
drwxr-xr-x 7 root staff 238 Nov 21 15:20 finalhandler
drwxr-xr-x 7 root staff 238 Nov 21 15:20 forwarded
drwxr-xr-x 7 root staff 238 Nov 21 15:20 fresh
drwxr-xr-x 7 root staff 238 Nov 21 15:20 http-errors
drwxr-xr-x 8 root staff 272 Nov 21 15:20 iconv-lite
drwxr-xr-x 7 root staff 238 Nov 21 15:20 inherits
drwxr-xr-x 7 root staff 238 Nov 21 15:20 ipaddr.js
drwxr-xr-x 7 root staff 238 Nov 21 15:20 media-typer
drwxr-xr-x 7 root staff 238 Nov 21 15:20 merge-descriptors
drwxr-xr-x 7 root staff 238 Nov 21 15:20 methods
drwxr-xr-x 11 root staff 374 Nov 21 15:20 mime
drwxr-xr-x 8 root staff 272 Nov 21 15:20 mime-db
drwxr-xr-x 7 root staff 238 Nov 21 15:20 mime-types
drwxr-xr-x 6 root staff 204 Nov 21 15:20 ms
drwxr-xr-x 8 root staff 272 Nov 21 15:20 negotiator
drwxr-xr-x 7 root staff 238 Nov 21 15:20 on-finished
drwxr-xr-x 7 root staff 238 Nov 21 15:20 parseurl
drwxr-xr-x 7 root staff 238 Nov 21 15:20 path-to-regexp
drwxr-xr-x 7 root staff 238 Nov 21 15:20 proxy-addr
drwxr-xr-x 12 root staff 408 Nov 21 15:20 qs
drwxr-xr-x 7 root staff 238 Nov 21 15:20 range-parser
drwxr-xr-x 8 root staff 272 Nov 21 15:20 raw-body
drwxr-xr-x 7 root staff 238 Nov 21 15:20 safe-buffer
drwxr-xr-x 9 root staff 306 Nov 21 15:20 safer-buffer
drwxr-xr-x 8 root staff 272 Nov 21 15:20 send
drwxr-xr-x 7 root staff 238 Nov 21 15:20 serve-static
drwxr-xr-x 8 root staff 272 Nov 21 15:20 setprototypeof
drwxr-xr-x 8 root staff 272 Nov 21 15:20 statuses
drwxr-xr-x 6 root staff 204 Nov 21 15:20 toidentifier
drwxr-xr-x 7 root staff 238 Nov 21 15:20 type-is
drwxr-xr-x 7 root staff 238 Nov 21 15:20 unpipe
drwxr-xr-x 7 root staff 238 Nov 21 15:20 utils-merge
drwxr-xr-x 7 root staff 238 Nov 21 15:20 vary
Step 2: Content of package.json
If you go inside the package.json, you will see two dependencies
@sap/cds is the module which is inside folder node_modules/@sap/cds.
Here you will find server.js which is actually the file which is run when you execute
a CAP Project with cds run command.
Content inside node_modules/@sap/cds
root@apples-MacBook-Air:~/Desktop/Blog/capm1/demo1/demop/node_modules/@sap/cds$ ls -l
total 928
-rw-r--r-- 1 Ajay staff 25104 Nov 15 21:06 CHANGELOG.md
-rw-r--r-- 1 Ajay staff 746 Nov 15 21:06 README.md
-rw-r--r-- 1 Ajay staff 396160 Nov 18 12:48 SIGNATURE.SMF
drwxr-xr-x 5 Ajay staff 170 Nov 21 15:20 _i18n
drwxr-xr-x 10 Ajay staff 340 Nov 21 15:20 apis
drwxr-xr-x 20 Ajay staff 680 Nov 21 15:20 bin
-rw-r--r-- 1 Ajay staff 3619 Nov 15 21:06 common.cds
-rw-r--r-- 1 Ajay staff 12591 Feb 28 2017 developer-license-3.1.txt
drwxr-xr-x 3 Ajay staff 102 Nov 21 15:20 etc
drwxr-xr-x 12 Ajay staff 408 Nov 21 15:20 lib
drwxr-xr-x 53 root staff 1802 Nov 21 15:20 node_modules
-rw-r--r-- 1 Ajay staff 7293 Nov 15 21:06 npm-shrinkwrap.json
-rw-r--r-- 1 Ajay staff 9574 Nov 21 15:20 package.json
-rw-r--r-- 1 Ajay staff 1517 Nov 15 21:06 server.js
Step 4: Create a simple Service
Create srv
First, we create a folder with name srv inside the project directory
mkdir srv
Create js
then we create a file mySimpleService.js which is going to contain our service
touchmySimpleService.js
Implement js
then, we create a module which holds our service, in simple js we can write as
the same code we can write using ES6 and arrow notation as
//this code is same as above but with arrow(=>) function
module.exports = srv => {
srv.on("somesrv", req => {
return"Hello " + req.data.msg;
});
};
Create cds service
Create a new file with name mySimpleService.cds in same folder of srv.
Here the name of the cds file can be different from js file but to keep
track of our service we have named it same
touchmySimpleService.cds
Add Service as function
then, we will add same service name which we exported in above js file
service exportSRV {
functionsomesrv(msg:String)returnsString;
}
Run project
So, far we have two files one js and one cds. Now we come to root of project and
run it with command cds run
cds run
You will see a message in console that server is running in port 4004
apples-MacBook-Air:/Users/apple/Desktop/Blog/camp2/demop# cds run
[cds] - serving exportSRV at /exportsrv - with impl: srv/mySimpleService.js
[cds] - service definitions loaded from:
srv/mySimpleService.cds
[cds] - launched in: 1949.628ms
[cds] - server listening on http://localhost:4004 ...
[ terminatewith ^C ]
🙂 Congratulations! You have now a Simple CAP Service Working.
Before we end!
In this 7 blog series, we are going to provide a small end-to-end scenario to work with SAP® CAPM. Here the usecase we are going to use is of Learning Management System(LMS).
Link to Master(or Main) Blog from which all the other blogs can be reached is Here.
If you wanted to check out the detailed course on SAP® CAPM the link is Here.
If you want to get learn SAP® Cloud Platform Development in Detailed then we have a 35hrs hands-on course Here.
For current offers and discounts check offer page Here.
In this 7 blog series, we are going to provide a small end-to-end scenario to work with SAP® CAPM. Here the usecase we are going to use is of Learning Management System(LMS) and build a Student List App and Deploy it to SCF.
Link to Master(or Main) Blog from which all the other blogs can be reached is Here.
If you wanted to check out the detailed course on SAP® CAPM the link is Here.
If you want to get learn SAP® Cloud Platform Development in Detailed then we have a 35hrs hands-on course Here.
For current offers and discounts check offer page Here.
In this section we are going to install SAP® CAPM library in our local computer
Prerequisite:
You need to have NodeJS installed(official NodeJS site here and all versions for download from here) in your machine(v10.5 is what we have used).
Also, NPM(Node Package Manager) would automatically get installed with NodeJS.
Step 1: Set NPM registry of SAP®
NPM registry points to a place where libraries are present. When NPM installs a package, then it looks to that place to find the library.
Example: Suppose, you have a registry at www.mycoolrepo.com where you are having your xyz library(or module).
When you use npm install xyz it should search your www.mycoolrepo.com for the xyz module, then download that to the current project where you are working.
In the case of CAPM and related development, we are going to use https://npm.sap.com NPM registry to install required Node Modules. Use below command to set this:
npm set @sap:registry=https://npm.sap.com
Step 2: Confirm installation
We will list all the NPM repository present in our computer
npm config list
On successful Installation we will see npm.sap.com as registry:
Step 3: Install @sap/cds
@sap/cds will provide us cds command access in terminal/command prompt.
Using cds we will be able to:
Create
Run
Build
CAPM Code Locally.
We can -g flag with the command to install @sap/cds-dk globally, use command below to install the cds-dk library globally:
npminstall-g @sap/cds-dk
Step 4: Confirm installation
To confirm installation of @sap/cds use command
cds
You will get the output as shown below
USAGE
cds <command> [<args>]
cds <src> = cds compile <src>
cds = cds help
COMMANDS
i | init jump-start cds-based projects
c | compile process models selectively
m | import add models from external sources
s | serve run servers locally
r | repl read-eval-event loop
e | env get/set cds configuration
b | build preparefor deployment
d | deploy e.g. to databases or cloud
v | versiongetdetailedversion information
? | help getdetailed usage information
Learn more about eachwith:
cds help <command> or
cds <command> ?
Step 5: Search modules inside registry
You can search inside https://npm.sap.com registry to see all
packages it contains with command:
In this 7 blog series, we are going to provide a small end-to-end scenario to work with SAP® CAPM. Here the usecase we are going to use is of Learning Management System(LMS).
Link to Master(or Main) Blog from which all the other blogs can be reached is Here.
If you wanted to check out the detailed course on SAP® CAPM the link is Here.
If you want to get learn SAP® Cloud Platform Development in Detailed then we have a 35hrs hands-on course Here.
For current offers and discounts check offer page Here.
In this 7 blog series, we are going to provide a small end-to-end scenario to work with SAP® CAPM. Here the usecase we are going to use is of Learning Management System(LMS) and build a Student List App and Deploy it to SCF.
Link to Master(or Main) Blog from which all the other blogs can be reached is Here.
If you wanted to check out the detailed course on SAP® CAPM the link is Here.
If you want to get learn SAP® Cloud Platform Development in Detailed then we have a 35hrs hands-on course Here.
For current offers and discounts check offer page Here.
Now let’s start this series with a little background about SAP® CAPM
SAP® Cloud Application Programming Model(CAPM) is a set of Library, Tools, Language and Framework from SAP® for building Apps.
The main reason for creating CAPM is to
Provide a Simple way to Create Cloud-Based Apps
The Apps and code which developer created can be made more reusable as modules
Advantage of Microservice can be utilized
Apps in Cloud can be easily integrated with Cloud Services(like DB service, message broker service or Auth Provider service)
A developer can focus more on the functional side of problem-solving
The 2 main Principle of SAP® CAPM are:
Declarative Approach: Focus on Outcome, not on Way!
Service-Based Approach: Get the Functionality from Service
Declarative Approach
So, if you are a developer you need to focus more on understanding the functional side which is what customer needs now, and also thinking about how can the App/Platform you are developing will evolve over time. Keeping this in mind you need to keep your current development modular, so it can allow future changes easily or your current development can be reused in the future easily.
Service-Based Approach
In CAPM all functionalities need to be broken down as service(s). In CAPM Services are stateless which means there is no record of previous interactions and each interaction request has to be handled based entirely on information that comes with it. You will also see, that to implement new service/functionality we will many times query existing service(s).
#2: Developer Stack
That Sounds Great! But you might be having questions like How it is Build and How as a developer you will work with it?
CAPM Lib are Predominantly Build With NodeJS, so you need to have basic know-how of NodeJS
We will use a lot of CDS code, may it be for building data structure(entity model/Table Structure), creating services(with functions) or even creating UI(with CDS Annotations)
You will find many out of the box tools which are part of CAPM, for example for running Apps with Fiori® Preview just with developed service, for building data structure to deploy in Database like HANA®, Sqlite or Other Other and many more surprises!
Prerequisite and Getting Started
We will create a simple End-to-End CAPM App using HDI Container in SAP® Cloud Foundry from Scratch.