Skip to Content
Technical Articles
Author's profile photo Munish Suri

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.

view more

 

So lets get started 

Prerequisite

  1. SAP Cloud Platform Account (Foundry ) – Data center available  
  2. Subscribed to SAP Business Application Studio
  3. Relevant Roles for accessing the service – Authorization Management
  4. 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

  1. 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

  1. 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;
    
    }
    
  2. 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;
    }​
  3. From terminal navigate to cd product-service using terminal.
  4. type mvn clean install – to compile the project using terminal .
  5. 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​
  6. installing SAP HANA DB deployer
    npm install --save-dev --save-exact @sap/hdi-deploy@3.7.0​
  7. login into CF account – using terminal type cf login and select the space
  8. 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​
  9. Go to srv->pom.xml and add the dependency
    <dependency>
            <groupId>com.sap.cds</groupId>
            <artifactId>cds-feature-hana</artifactId>
        </dependency>​
  10. Time to run the application in the terminal
    mvn spring-boot:run -Dspring-boot.run.profiles=cloud​

     

     

  11. Click on Expose and Open on the left Bottom and press Enter
  12. Go Back to Application Studio and open new terminal
  13. 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 }' 
  14. 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.

Assigned Tags

      17 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Ervin Szolke
      Ervin Szolke

      Hi,

      I also found new and updated tutorials about this topic.

      New SAP Business Application Studio On-Boarding Before you can start developing using SAP Business Application Studio, administrators must perform the required onboarding steps that are described in this tutorial.
      Updated Developing SAP Fiori App Using SAP Business Application Studio Create an SAP Fiori application in SAP Business Application Studio and deploy it to your SAP Cloud Platform, Cloud Foundry environment

      Cheers,

      Ervin

      Author's profile photo Rekha Patadiya
      Rekha Patadiya

      Thanks Munish Suri  for providing a step-by-step guide. 🙂

      Author's profile photo Sam Sun
      Sam Sun

      Excellent, Really Helpful.

      Author's profile photo Former Member
      Former Member

      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

       

      Author's profile photo Justin Broughton
      Justin Broughton

      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

       

      Author's profile photo Yordan Pavlov
      Yordan Pavlov

      Hi Munish,

       

      I'm also stuck to step 8:

       

      /home/user/projects/products-service/node_modules/@sap/hdi-deploy/node_modules/@sap/hana-client/lib/index.js:123
              throw ex;
              ^
      Error: Failed to load DBCAPI.
          at internal/modules/cjs/loader.js.Module._extensions..node (internal/modules/cjs/loader.js:807:18)
          at internal/modules/cjs/loader.js.Module.load (internal/modules/cjs/loader.js:653:32)
          at internal/modules/cjs/loader.js.tryModuleLoad (internal/modules/cjs/loader.js:593:12)
          at internal/modules/cjs/loader.js.Module._load (internal/modules/cjs/loader.js:585:3)
          at internal/modules/cjs/loader.js.Module.require (internal/modules/cjs/loader.js:692:17)
          at internal/modules/cjs/helpers.js.require (internal/modules/cjs/helpers.js:25:18)
          at /home/user/projects/products-service/node_modules/@sap/hdi-deploy/node_modules/@sap/hana-client/lib/index.js (/home/user/projects/products-service/node_modules/@sap/hdi-deploy/node_modules/@sap/hana-client/lib/index.js:115:14)
          at internal/modules/cjs/loader.js.Module._compile (internal/modules/cjs/loader.js:778:30)
          at internal/modules/cjs/loader.js.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
          at internal/modules/cjs/loader.js.Module.load (internal/modules/cjs/loader.js:653:32)
      
      
      [ERROR] [cds.deploy] - HDI deployment failed with exit code 1

       

      Regards,

      Yordan

      Author's profile photo Munish Suri
      Munish Suri
      Blog Post Author

      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

      Author's profile photo Peter Alexander
      Peter Alexander

      Hi Munish,

      How do I deploy the application on CF?
      As MTA?
      Which steps do I have to go through?

      Thanks
      Peter

      Author's profile photo Munish Suri
      Munish Suri
      Blog Post Author

      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

      Author's profile photo Robin Reeb
      Robin Reeb

      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

      Author's profile photo Munish Suri
      Munish Suri
      Blog Post Author

      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

      Author's profile photo Swetha Balusamy
      Swetha Balusamy

      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.

      Author's profile photo Munish Suri
      Munish Suri
      Blog Post Author

      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

      Author's profile photo Louis Huang
      Louis Huang

      I got the same error. Can you help me?

      Author's profile photo Munish Suri
      Munish Suri
      Blog Post Author

      Hi Louis,

       

      Can you please try in SAP Cloud Platform Test account, not the canary one.

       

      Best regards

      Munish Suri

      Author's profile photo Christian Tapia
      Christian Tapia

      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:

      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 ]

      Best regards.

      Author's profile photo Munish Suri
      Munish Suri
      Blog Post Author

      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