As CRUD operations are possible in SAP UI5 using XSJS services (SAP HANA as database) but as per new versions of Odata Model these operations are possible through ODATA. It reduces considerable lines of code and makes SAP UI5 more friendly for developers.

Following artifacts are used in this Document-

  • A SAP HANA Table – “”.”DATA” which contains three columns- NAME (NVARCHAR), CITY(NVARCHAR), PHONE(INTEGER)
  • A Odata service is created DATA.xsodata
  • A Demo SAP UI5 Application is created having Table contents in home Screen and having separate buttons for “ADD, “UPDATE”, “DELETE” operations.
  • “ADD” & “UPDATE” Buttons opens dialogs having three Input Fields for each column of Table

Let us have a look on SAP UI5 Application used in this Demo. Please note that coding part of this application is not discussed here, As this article is focussed only on CRUD operations:

Home Screen of Application

Odata Service

service {

“SCHEMA”.”DATA” as “DATA”;

}

Odata READ Operation:

It is simplest operation and already widely used in development. For this, a OdataModel is to be instantiated in Application. Then this Model is to be bind to UI Element, here, Table

var oModel = new sap.ui. model. odata. ODataModel(“DATA.xsodata”);

  1. sap.ui. getCore (). setModel(oModel);

Note: Service Path may be different with respect to your package Structure.

 

This Odata service will load complete data of HANA Table in UI5 Application.

Odata CREATE Operation:

Once user click on “ADD” button on Home Screen, a Dialog will open for New Entry creation in table

 

Once user Clicks on “Add” in Dialog, it will trigger a function in Controller-

 

  • mNewEntry is a Javascript Object. It is used as oModel.create() method can only accepts String Data
  • I1, I2, I3 are IDs of Input Fields in Dialog.

Odata UPDATE Operation:

For this, Use has to select a row to be updated. The values of that row will appear in UPDATE Dialog in editable input fields.

 

Once user changes values, new values will be updated in HANA Table on clicking “Update” icon, which will call a function as –

Function(odata){} will be be called if Update is successful otherwise, Function(err) will be called. You can show any message in these function (Message Box usage is not mandatory).

Both Success & Error functions are optional to be defined.

 

Odata DELETE Operation:

For this operation, more than 1 row can be selected simultaneously to be deleted. Once those rows are selected “DELETE” button will trigger a function as-

aBatchtoDelete will hold ‘sPath’ of rows to be deleted. createBatchOperations are performed to Create/Delete Multiple records simultaneously. For more properties, please refer API Reference.

_____________________________________

New NetWeaver Information at SAP.com

Very Helpfull

 

 

User Rating: Be the first one !