Skip to Content
Author's profile photo Monalisa Biswal

Step-By-Step process to develop UI5 Application on HANA DB

Introduction

The tutorial will demonstrate how to build application on HANA DB using UI5.

Integration of UI5 application with HANA DB happens in 3 step process:

    1. Creation of modeling  objects ( e.g. TABLES or VIEWS)
    2. Exposing modeling objects in an ODATA service
    3. Consuming ODATA service in UI5 Application

The document gives step-by-step process starting from creation of modelling object in HANA modeler, then exposing it into odata service and finally consume in UI5 application.

For the tutorial we will create an attribute view in HANA model from ECC table(T001W), expose the view in odata service and display the data from the attribute view in the UI5 application.

1. Creation of ATTRIBUTE View:

 

For this tutorial I am assuming we already have sourced tables from ECC to HANA systems.

  • Go to Modeler Perspective in HANA Studio.

     Picture0.gif

· 

  • Expand Content folder in the HANA system and Right click on the Content Folder to create a package.

     Picture1.gif

  • Right click on the package and Click on New Attribute View. Give a name for the attribute view and click ok.

     Picture2.gif

  • Double click on attribute to open its editor.

     Picture3.gif

  

  • Open Catalog folder to select a table on which the attribute view will be created.

Picture4.gif

  • Drag Table from left hand pane and Drop it at the Data Foundation Section.

Picture5.gif

  • Right Click on the fields or highlight the gray icon besides the fields in Details View to add them in the output.

Picture6.gif

  • Click on Save and activate to commit and activate changes done in attribute view.

Picture29.gif

  • Click on Data Preview to check the data of Attribute View.

Picture30.gif

  • Click on Raw Data tab to view the tabular data.

Picture9.gif

2. Exposing Attribute View in an ODATA Service

  • Go to HANA Development perspective

Picture10.gif

  • Create new  XS Project to store the service definition for odata service.

Picture11.gif

  • Give a name to the project (e.g. PlantService).

Picture12.gif

  • Create two files in the project.

.xsapp . A blank file with name “.xsapp”

.xsaccess. Write following in the file

{ “exposed” : true, “authentication” : [ { “method” : “Basic” } ] }Picture13.gif

Picture14.gif

Picture15.gif

    

   

  • Create  a file with .xsodata(e.g. PlantOData.xsodata) extension which will have code for exposing attribute view into ODATA service .

  Picture16.gif

  • Write following piece of code in PlantOData.xsodata to expose the attribute view we have created before into odataservice.

       service {

//<PACKAGE NAME>::<ATTRIBUTE_VIEW NAME> as <RESULT SET NAME>

trng::AT_PLANT_VIEW” as “PlantView”

keys generate local “ID”;

}

  • Save all your changes. Right Click on PlantService folder to share, commit and activate to the HANA Repository.

       Picture17.gif

     Picture19.gif

     Picture20.gif

  • Once the odata service is activated, you will be able to test it on the browser.

Pass $metadata as query string to view the metadata for odataservice.

                    http://<HOST>:<PORT>/PlantService/PlantOData.xsodata/$metadata

               Picture21.gif

You can view the data from attribute view by passing resultset name given in the odata service definition file(e.g. PlantView) in the URL.

                                   http://<HOST>:<PORT>/PlantService/PlantOData.xsodata/PlantView

  3.  Consuming ODATA service in UI5 Project

  • In Hana Development perspective click on File ->New->Other->SAP UI5 Application Development->Application Project to Create UI5 Project.

     Picture22.gif

  • Give a name to the UI5 Project(e.g. plantlist), select Target Device as “Desktop”, Leave the “Create an Initial View “ checkbox checked.

Picture23.gif

  • Give the View Name (e.g. PlantListView). Leave Default JAVASCRIPT option selected. Click on Finish.

Picture24.gif

  • You will see following files created in the project:
      • Index.html
      • PlantListView.view.js               
      • PlantListView.controller.js

Picture25.gif

  •     To refer the UI5 core library installed on hana server, change the path in “index.html” as follows and add sap.ui.table library to include table element on screen:

<script src=“/sap/ui5/1/resources/sap-ui-core.js”

                        id=“sap-ui-bootstrap”

                        data-sap-ui-libs=“sap.ui.commons,sap.ui.table

                        data-sap-ui-theme=“sap_goldreflection”>

        </script>

  • In the html file declare a variable to store URL for the odata service.

     var oDataUrl= http://hostname:portnumber/PlantService/PlantOData.xsodata/;

  • Declare a variable to create odata model from the service.

     var oDataModel= newsap.ui.model.odata.ODataModel(oDataUrl);

Picture26.gif

  • Write following code in createContent method of PlantListView.view.js to create table element on view and bind to the odata model.

       createContent : function(oController) {

              varoPlantTable = newsap.ui.table.Table({

                     visibleRowCount: 10,

                     threshold:100,

                     width : “500px”,

           

              });

              //Define the columns and the control templates to be used

              oPlantTable.addColumn( newsap.ui.table.Column({

                     label: newsap.ui.commons.Label({text: “Plant”}),

                     template: newsap.ui.commons.TextView().bindProperty(“text”, “WERKS”),

                     sortProperty: “WERKS”,

                     filterProperty: “WERKS”,

                     width: “40px”

              }));

              oPlantTable.addColumn(newsap.ui.table.Column({

                     label: newsap.ui.commons.Label({text: “Name”}),

                     template: newsap.ui.commons.TextView().bindProperty(“text”, “NAME1”),

                     sortProperty: “NAME1”,

                     filterProperty: “NAME1”,

                     width: “120px”

              }));

           

              oPlantTable.addColumn(newsap.ui.table.Column({

                     label: newsap.ui.commons.Label({text: “Street”}),

                     template: newsap.ui.commons.TextView().bindProperty(“text”, “STRAS”),

                     sortProperty: “STRAS”,

                     filterProperty: “STRAS”,

                     width: “120px”

              }));

              oPlantTable.addColumn(newsap.ui.table.Column({

                     label: newsap.ui.commons.Label({text: “City”}),

                     template: newsap.ui.commons.TextView().bindProperty(“text”, “ORT01”),

                     sortProperty: “ORT01”,

                     filterProperty: “ORT01”,

                     width: “80px”

              }));

           

              oPlantTable.setModel(oDataModel);

              oPlantTable.bindRows(“/PlantView”);

              returnoPlantTable;

           

       }

  • Create .xsaccess and .xsapp file in the project same way we have created in PlantService project.

Picture27.gif

  • Save all files. Right click on the project root folder to share to the workspace, commit and activate it.
  • Your Ui5 application can now be tested at following URL:

     http://<hostname>:<port>/<package: if shared to a package>/plantlist/WebContent/index.html

     Picture28.gif

Assigned Tags

      7 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Good One..this is for read. how do you enable the write back functionality.?

      Author's profile photo Monalisa Biswal
      Monalisa Biswal
      Blog Post Author

      Thanks Srinivas! Odata model has set of methods to allow other CRUD operations. I will publish them in another document.

      Author's profile photo Bhuvaneshwari M
      Bhuvaneshwari M

      Hi Monalisa,

      Very informative blog!

      I want to do CRUD operation bw UI5 App - HANA tables via Odata services. How can i do it ?

      Can you share blog/documents to achieve the functionality.

      Thanks.

      Author's profile photo brahmanandam ausali
      brahmanandam ausali

      Nice and very informative blog 🙂

      Author's profile photo Monalisa Biswal
      Monalisa Biswal
      Blog Post Author

      Thanks!

      Author's profile photo Meng Yuxin
      Meng Yuxin

      good document for junior developer. Thanks a lot.

      Author's profile photo Former Member
      Former Member

      I tried many tutorials but this tutorial helped me a lot. Thanks a lot