Call oData Service in Fiori App


In this tutorial, we will talk about OData model and hand hold you to create a front-end application and call the OData Model to perform the CRUD Operations.
Using OData Model, you can consume the OData Service. For this we need to create an OData Service and implement CREATE, READ, UPDATE and DELETE methods of the service. Then we need to create an OData Model Instance in the UI5 application and call these methods using read(), create(), update() and remove() functions respectively of the OData model.
So let’s start…
Business scenarioCustomer wants to display records from a custom table onto the UI5 application and provide functions of Read, Create, Update and Delete to the end users.

Step 1: Get a Custom Table ready for us to play

Creating a custom table by the name ‘zuserdata’ with id, name, email and mobile fields.

Step 2: Creating an OData service

  1. Go to transaction SEGW and create a new OData Service, name it zcrud_demo.
Please note : If you are completely new to OData Service, then we would suggest you to take the tutorial where we have created our first OData Service.
Also Note : You can also take this Free Video Course on OData Service and Netweaver Gateway.
  1. Create an entity ‘userdata’ and create associated entityset as well ‘userdataSet’.
  2. Create 4 properties in ‘userdata’ entity namely id, name, email and mobile.
  3. Ensure Properties datatype and length matches with that of the fields created in table in step1.
  4. Activate the OData service which will generate its runtime artifacts.
  5. Redefine Create, Read, Update and Delete methods of …DPC_EXT Class of the oData service.
7. Write your logic (code) in each of the redefined methods (Redefinition code is given in below part of the tutorial)
8.  Go to t-code /n/iwfnd/maint_service and Add the Service.
9. Perform ICF settings for the generated OData service to enable Create operations using OData model. Go to SICF transaction, open OData service’s ICF node and double click on it, Click on GUI Configuration button.
Set ~CHECK_CSRF_TOKEN value to 0. This will bypass CSRF protection on the service. This is required for CREATE, UPDATE and DELETE operations to work. If you don’t want this protection to be turned off (from a security perspective), you need to fetch X-CSRF-TOKEN using READ operation every time you want to perform CREATE, UPDATE or DELETE operations from UI5 application. In this tutorial, for the sake of simplicity, we have chosen to turn off X-CSRF-TOKEN security feature.
OData ABAP code for Create – CREATE_ENTITY Method
OData ABAP code for Get (Single record) – GET_ENTITY method
OData ABAP Code for Get (multiple records) – GET_ENTITYSET Method
OData ABAP code for Update – UPDATE_ENTITY Method
OData ABAP code for Delete – DELETE_ENTITY Method

Step 3: Create SAPUI5 Application

Create SAPUI5 application to Consume OData Service created in Step 2 and Call CREATE, READ, UPDATE and REMOVE functions of the OData model.
  1. Create a new SAPUI5 application by the name crud_demo.
  2. Create a XML view ‘crud_demo.view’. Write below code in it.

    3. Create crud_demo.controller.js. Write below code in it.
4. Save, Deploy and Run the application. You should be able to run the application using below URL
http://hostname:8000/sap/bc/ui5_ui5/sap/zcrud_demo/index.html

Output:-



You should be able to create the above simple application.ll the buttons should work as expected. If you face any issue, please do not hesitate to write your questions in the comments section below. You can also email us at install.abap@gmail.com



Comments

Popular posts from this blog

Difference between Rest and OData ?

ABAP Managed Database Procedures – Introduction