Technical Articles
SAP Business Application Studio – Getting Started with CAP and SAP HANA Service on CF
In the new era of cloud , where we are moving towards Cloud Foundry environment , a next generation development environment is also required catering to the needs of developer.
Hence SAP Business Application Studio.
What is it ????
SAP Business Application Studio is a next generation, tailor made development environment available as a service on SAP Cloud Foundry which offers a modular development for business application for SAP Intelligent Enterprise.
Here developers can utilize more than 1 development space which are isolated from each other and let you run the application without deploying on Cloud Platform using its powerful terminal
CAP – SAP Cloud Application Programming Model
it is an open and opinionated model , which provides framework of libraries , languages and tools for the development of enterprise grade applications . It provides some best practices and guides developer with out of the box solutions for some common problems.
So lets get started
Prerequisite
- SAP Cloud Platform Account (Foundry ) – Data center available
- Subscribed to SAP Business Application Studio
- Relevant Roles for accessing the service – Authorization Management
- SAP HANA Service hdi-shared
After Accessing the application
Create a Dev Space
Step 1 : Click on Create Dev Space
Step 2: Create Dev Space – Enter Name and Select SAP Cloud Business Application as a category
Start Developing
- Open new terminal
2. type cd projects , to change the directly.
3. setting up the project
mvn -B archetype:generate -DarchetypeArtifactId=cds-services-archetype -DarchetypeGroupId=com.sap.cds \
-DarchetypeVersion=1.2.0 -DcdsVersion=3.21.2 \
-DgroupId=com.sap.teched.cap -DartifactId=products-service -Dpackage=com.sap.teched.cap.productsservice
Open your project in the Studio
Lets Make CDS files
- Navigate to db , create a file schema.cds
namespace sap.capire.dev; entity Products { title : localized String(20); descr : localized String(100); stock : Integer; price : Decimal(9,2); key id :Integer; }
- Navigate to srv , create a file service.cds
using { sap.capire.dev as db } from '../db/schema'; service AdminService { entity Products as projection on db.Products; }
- From terminal navigate to cd product-service using terminal.
- type mvn clean install – to compile the project using terminal .
- Now go to srv -> src -> main -> resources and open application.yaml and replace the content
--- spring: profiles: default datasource: url: "jdbc:sqlite:/home/user/projects/products-service/sqlite.db" driver-class-name: org.sqlite.JDBC initialization-mode: never
- installing SAP HANA DB deployer
npm install --save-dev --save-exact @sap/hdi-deploy@3.7.0
- login into CF account – using terminal type cf login and select the space
- initialize DB and create SAP HANA Service instance – please make sure , you have the entitlement using terminal type , kindly type it manually
cds deploy --to hana:bookstore-hana
- Go to srv->pom.xml and add the dependency
<dependency> <groupId>com.sap.cds</groupId> <artifactId>cds-feature-hana</artifactId> </dependency>
- Time to run the application in the terminal
mvn spring-boot:run -Dspring-boot.run.profiles=cloud
- Click on Expose and Open on the left Bottom and press Enter
- Go Back to Application Studio and open new terminal
- Test the service with POST call
curl -X POST http://localhost:8080/odata/v4/AdminService/Products \ -H "Content-Type: application/json" \ -d '{ "title": "Product 1", "descr":"sample product ","stock":20,"price":100.60,"id":1 }'
- Now Lets check the service from step 11 , open Products and you shall be able to view the saved data
After successfully following these steps , you would be able to complete the setting up of SAP Business Application Studio on SAP Cloud Platform (Foundry) , creating an application using CAP , connecting it to SAP HANA Service and performing POST , GET operation on your ODATA service.
These are the screenshots taken from our SAP Cloud Platform account.
Hi,
I also found new and updated tutorials about this topic.
Cheers,
Ervin
Thanks Munish Suri for providing a step-by-step guide. 🙂
Excellent, Really Helpful.
Hi Munish,
nice cookbook tutorial approach...and it worked for me nicely up to point 8 where it simply crashed with this message:
Service offering 'hanatrial' not found.
will take another look after switching my eu and us spaces around, but thank you for the steps 1-7.
rgds,
greg
Hi Greg,
I also ran into an issue
[ERROR] [cds.deploy] - Service name bookstore-hana must only contain alpha-numeric, hyphens, and underscores.
, however when I retyped manually the execution was successfull.
Regards
Justin
Hi Munish,
I'm also stuck to step 8:
Regards,
Yordan
Hi Yordan,
Please create an instance of hana HDI . you may utilise hanatrial service on cloud foundry for the same.
HDI - use the name bookstore-hana
Best regards
Munish
Hi Munish,
How do I deploy the application on CF?
As MTA?
Which steps do I have to go through?
Thanks
Peter
Hi Peter,
for deploying , you may have to create a manifest.yml .
Where you have to define the name , path(jar) ,services .
and using cf push , you should be able to deploy on cloud platform.
Best regards
Munish
Hi Munish, probably not the best place to ask this one, but I’ll try anyway.
There is an issue I couldn’t overcome so far.
When I want to clone a git repo from SAPs internal Github, it gives me
.
fatal: unable to access ‘https://github.wdf.sap.corp/<my repo url>/’: Received HTTP code 502 from proxy after CONNECT
I would assume connecting to git repos should be supported out of the box.
Thanks!
Robin
Hi Robin,
In the terminal, you can clone the git repository.
As i see you are trying to clone the internal Git Repository, which i guess wont be possible on the public version.
Maybe you can give it a try in the internal canary account if possible.
thanks
Best regards
Munish
Hi Munish,
Nice blog.
When I do cds delpoy , I get the following error.
Deployment to container CC3087871C54427590C88E8F653E85DF failed - error: Could not connect to any host: [ 2c6c06c9-3e72-4b4b-bc1c-696367460cad.hana.canary-eu10.hanacloud.ondemand.com:443 - Client network socket disconnected before secure TLS connection was established ] [Deployment ID: none].
Error: Could not connect to any host: [ 2c6c06c9-3e72-4b4b-bc1c-696367460cad.hana.canary-eu10.hanacloud.ondemand.com:443 - Client network socket disconnected before secure TLS connection was established ]
Any idea why this is happening?.
Regards,
Swetha.
Hi Swetha,
It seems you are trying to connect with the Canary account.
Unfortunately, I have used the factory account.
Can you please raise an internal ticket for the same?
Best regards
Munish Suri
I got the same error. Can you help me?
Hi Louis,
Can you please try in SAP Cloud Platform Test account, not the canary one.
Best regards
Munish Suri
Hello,
Is it possible to use "cds deploy ..." to test in a HANA DB from another subaccount/org/space? I already followed all the steps from documentation in order to deploy, but I'm now quite sure if "cds deploy" should work with this setup.
The error I get is similar to the one posted by Swetha:
Best regards.
Hello Christian,
Can you please try in SAP Cloud Platform Test account, it works usually.
I am not really sure of the canary account.
Kindly raise an internal ticket if the problem persists.
Best regards
Munish Suri