Skip to Content

SAP HANA Native, Create a User Interface with the Cloud Application Programming Model

0 %
SAP HANA Native, Create a User Interface with the Cloud Application Programming Model

SAP HANA Native, Create a User Interface with the Cloud Application Programming Model

January 27, 2021
Created by
July 25, 2019
Use services based on Node.js and use an SAP Fiori wizard to create a user interface.

You will learn

  • How to create an HTML5 web interface
  • How to configure the approuter
QR code


  • This tutorial is designed for SAP HANA on premise and SAP HANA, express edition. It is not designed for SAP HANA Cloud.
  • You have created a Multi-Target Application using the Cloud Application Programming Model.
  • You have created database artifacts and loaded data as explained in this tutorial.

Step 1: Build the services

Return to the code editor and right-click on the srv folder. In the file interaction_srv.cds you created the definition for two read-only services that expose the header and items entities in your database module.

Choose Run > Run as Node.js Application.

Run as Node.js application

You will see the run console shows the progress. Once the application is running, click the URL to open the service.

Run as Node.js application

You should see the list of entities you exposed.

Run as Node.js application

You can click on the entities to see the values in a JSON format.

Log on to answer question
Step 2: Test the services

Add $metadata to the service and you can see a technical description of the service (for example, https://hxehost:51026/catalog/$metadata ).

Run as Node.js application

You can use different methods in the OData v4 services you have created. Go back to the welcome page for the service and click Interactions_Items. Add the following to the URL:


For example, https://hxehost:51026/catalog/Interactions_Items?$search=DE:

Play with OData service

You can find out more about OData V4 at the OData organization and the documentation for SAPUI5.

Log on to answer question
Step 3: Configure routing

You will now create a basic web module. This module is very important as it will become the entry point for your application. Every request coming to this module will be routed into the different backend services.

Right-click on the project folder and choose New > Basic HTML5 Module (or just New > HTML5 Module if using the SAP Web IDE Full-stack).

Play with OData service

If using the SAP Web IDE Full-stack there will be a question here asking for template selection. Please choose SAPUI5 Application.

Call it web and click Finish.

Play with OData service

Since the web module will be receiving the requests and routing them into the proper processing backend services, such as the OData service you have just defined, it will also be responsible for enforcing authentication.

These routing logics are done by an application called approuter. You can see the Node.js module being called as the starting script for the web module as defined in the file package.json.

Play with OData service

The approuter will scan the file xs-app.json to route patterns in the request to the right destinations.

Replace the content of xs-app.json with the following content if you are using SAP Web IDE for SAP HANA:

{ "welcomeFile": "index.html", "authenticationMethod": "none", "routes": [{ "source": "/catalog/(.*)", "destination": "srv_api", "csrfProtection": true }] }

If you are using the SAP Web IDE Full-stack, use this code instead:

	"welcomeFile": "index.html",
	"authenticationMethod": "none",
	"routes": [{
		"source": "/catalog/(.*)",
		"destination": "srv_api",
		"csrfProtection": true
		"source": "^/web/(.*)$",
		"target": "$1",
		"localDir": "webapp"

Save the changes.

Web module

Among other information, this configuration is declaring that requests containing the pattern /catalog/(.*) are routed to a destination called srv_api.

This destination can be defined in the mta.yaml file.

Log on to answer question
Step 4: Edit the deployment descriptor

When an application is deployed, the mta.yaml file is used to establish the dependencies between the modules and resources. During this binding process, environment variables such as the name of the destinations are set.

Open the mta.yaml file and you will notice the srv module provides a variable called url. This variable is taking the value of the default URL provided at runtime.

Web module

Click on the web module. You will establish its dependency with the srv module and declare the destination. The name of the destination here needs to match the name you used in xs-app.json in the previous step.

  1. Add a new Requires entry for the web module.

  2. Choose srv_api under Requires in the dropdown.

  3. Enter destinations under Group.

  4. Fill in the properties with the following key-value pairs …

    Key Value
    name srv_api
    url ~{url}
    forwardAuthToken true

    … as follows:

    Web module
  5. Save the changes in the deployment descriptor file.

Here is what the file looks like in the code editor:

Web module

For more information and examples about the approuter, refer to this section in the help.

Log on to answer question
Step 5: Create a quick and dirty web interface

Open the index.html file generated by the wizard in your web module.

Replace the entire contents with the following code:

<!DOCTYPE html>
		<meta charset="utf-8">
	    <meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- 1.) Load SAPUI5 (from a remote server), select theme and control library -->
<script src=""
	id="sap-ui-bootstrap" data-sap-ui-libs="sap.m, sap.ui.table"


	var oModel = new sap.ui.model.odata.v4.ODataModel({  synchronizationMode : "None", serviceUrl : "/catalog/" });
	var oTable = new sap.ui.table.Table({ title: "My first table" });
	oTable.addColumn(new sap.ui.table.Column({ label: "Text", template: "LOGTEXT" }));

	<body class="sapUiBody">
		<div id="uiArea"></div>

Save the changes.

Web module

This very simple code is creating a model from the OData V4 service and using it in a table. This is only test code to show the consumption of the model, but there is a lot to improve here.

Run the srv module again.

Web module

Once the srv module is running, run the web module if you are using the SAP Web IDE for SAP HANA.

Web module

If you are instead using the SAP Web IDE Full-stack, please choose Run Configurations for the web module. Then select Run on Cloud Foundry and press the Save and Run button.

Web module

Congratulations! You have created your first application.

Web module

Now it is a good time to commit your application into the local or remote Git.

Log on to answer question

Next Steps

Back to top