Skip to Content

Create an application using SAP HANA and the Cloud Application Programming Model

Use SAP Web IDE and the Cloud Application Business wizard
You will learn
  • How to create a simple application based on the SAP Cloud Application Business wizard
  • You will be introduced to basics on cloud-native development and multi-target applications
jung-thomasThomas JungJanuary 27, 2021
Created by
Lsubatin
March 1, 2019
Contributors
jung-thomas
Lsubatin

Prerequisites

  • Step 1

    Right-click on workspace and choose Project from Template

    New project

    Make sure Cloud Foundry is the selected environment. Select SAP Cloud Platform Business Application and click Next

    New project

    Call the project APP and click Next

    New project

    Mark Use HTML5 application repository and click Next

    New project

    Change the database version to 2.0 SPS02

    New project
  • Step 2

    Expand the db folder and double-click on data-model.cds to expand it

    New project

    Replace the content in data-model.cds with the following:

    text
    Copy

    namespace my.app; entity Recipes{ key ID : Integer; instructions : String; dish : String; time : Integer; unit : String; ingredients : association to many Ingredients on ingredients.recipe = $self; }; entity Ingredients{ key ID : Integer; recipe : association to Recipes; quantity : Double; unit : String; ingredient : String; };

    For example:

    New project
  • Step 3

    Navigate into the srv folder. Double-click on cat-service.cds.

    New project

    Replace the existing content in cat-service.cds with the following

    text
    Copy
    using my.app from '../db/data-model';
    service CatalogService {
    
     entity Recipes
    	@readonly
    	as projection on app.Recipes;
    
     entity Ingredients
    	@readonly
    	as projection on app.Ingredients;
    
    }
    
    

    Save all files

    New project

    What is going on?

    You can see Core Data and Services generating design time artifacts based on SAP HANA (.hdbcds) under a new folder called db\src\gen. You can also follow progress by opening the console.

    New project
  • Step 4

    The .cds file in which you defined the entities for persistence was used to create files with extension .hdbcds. These files will be used by the deployment infrastructure to create physical objects, such as tables, in the database.

    Right-click on the db folder and choose Build

    Build database

    You can follow progress in the Console:

    Build database
  • Step 5

    Now that the database module has been built, you can explore the HDI container and the physical tables.

    Right-click on db and choose Open HDI Container.

    Build database

    Click on Tables. Right-click on MY_APP_INGREDIENTS and choose Generate INSERT statement.

    Build database

    Make a note of the name of the schema and table, as you may need to adjust the code.

    Use the following code to insert values into the table:

    sql
    Copy
    INSERT INTO "APP_HDI_CONTAINER"."MY_APP_INGREDIENTS" VALUES(1,175,'G','Softened Butter',1);
    INSERT INTO "APP_HDI_CONTAINER"."MY_APP_INGREDIENTS" VALUES(2,3,'UN','Egg',1);
    INSERT INTO "APP_HDI_CONTAINER"."MY_APP_INGREDIENTS" VALUES(4,4,'TBSP','Nutella',1);
    INSERT INTO "APP_HDI_CONTAINER"."MY_APP_INGREDIENTS" VALUES(5,250,'G','Nishiki Rice',2);
    INSERT INTO "APP_HDI_CONTAINER"."MY_APP_INGREDIENTS" VALUES(6,750,'ML','Water',2);
    INSERT INTO "APP_HDI_CONTAINER"."MY_APP_INGREDIENTS" VALUES(8,800,'G','Fresh salmon',2);
    INSERT INTO "APP_HDI_CONTAINER"."MY_APP_INGREDIENTS" VALUES(9,50,'G','Macaroni',3);
    INSERT INTO "APP_HDI_CONTAINER"."MY_APP_INGREDIENTS" VALUES(10,150,'ML','Water',3);
    INSERT INTO "APP_HDI_CONTAINER"."MY_APP_INGREDIENTS" VALUES(11,50,'G','Cheddar cheese',3);
    
    

    Hint: Ctrl+H allows you to replace the schema in the code above if necessary.

    Press F8 or use the Run button to insert the records

    Build database
  • Step 6

    Repeat the previous steps for the table MY_APP_RECIPES and use the following SQL statements to create data:

    sql
    Copy
    INSERT INTO "APP_APP_HDI_CONTAINER"."MY_APP_RECIPES" VALUES(1,'Mix the egg, butter and flour into a cup. Incorporate Nutella. Bake in microwave for 2 minutes','Nutella cupcake',15,'min');
    INSERT INTO "APP_APP_HDI_CONTAINER"."MY_APP_RECIPES" VALUES(2,'Lay a piece of nori on sushi mat. Spread rice. Add salmon. Roll','Salmon roll',1,'h');
    INSERT INTO "APP_APP_HDI_CONTAINER"."MY_APP_RECIPES" VALUES(3,'Mix the macaroni, water, and salt in a microwaveable mug. Microwave for 2-3 minutes','Mac and Cheese',7,'min');
    

    Right-click on MY_APP_RECIPES and choose Generate SELECT statement.

    Change the select clause to count the number of records to complete the validation below

    Build database

    What is the total number of records?

  • Step 7

    Go back to the code editor.

    Right-click on the srv folder and choose Build

    Build Java

    Wait until the process has finished and make sure the build has finished successfully in the console:

    Build Java

    Right-click on the module and choose Run as Java Application

    Run Java

    Once the application is running, click on the URL for the services.

    Run Java

    What is displayed when clicking on the URL in Web IDE?

  • Step 8

    Right-click on your app and choose HTML5 module

    Build web

    Choose SAP Fiori Worklist Application. Click Next

    Run Java

    Call the module web. Fill in the Title and Namespace and click Next

    Run Java

    Choose CatalogService and click Next

    Run Java

    Complete the data binding as follows and click Finish

    Run Java
  • Step 9

    Right-click on the web module and choose Run as Web Application

    Run Java

    Choose index.html

    Run Java

    If prompted, enter your credentials:

    Run Java

    Note: Your credentials are the same you used to log in to the SAP Cloud Platform trial account

    Congratulations! You have created your first multi-target application using the Cloud Application Programming Model. You can read more about Multi Target applications and SAP HANA in this series of blogs posts or about the Cloud Application Programming Model in the official SAP Documentation

    If you look into the SAP Cloud Platform Cockpit, you will see the Java micro-service running as an application:

    Run Java

    And the HDI container, with the SAP HANA database artifacts, listed in the services:

    Run Java

    Which recipe takes longer?

Back to top