0% found this document useful (0 votes)
75 views76 pages

Introduction To OData Services

The document provides an introduction to OData services within the context of SAP Fiori systems, detailing the architecture, communication methods, and responsibilities of SAP developers. It explains the OData protocol, its development using ABAP, and important transaction codes for managing OData services. Additionally, it outlines the process for developing OData services, including CRUD operations and testing methods.

Uploaded by

goldypawar18
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views76 pages

Introduction To OData Services

The document provides an introduction to OData services within the context of SAP Fiori systems, detailing the architecture, communication methods, and responsibilities of SAP developers. It explains the OData protocol, its development using ABAP, and important transaction codes for managing OData services. Additionally, it outlines the process for developing OData services, including CRUD operations and testing methods.

Uploaded by

goldypawar18
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 76

INTRODUCTION

OF
ODATA
SERVICES

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
󾠮
Introduction
1. Architecture of SAP Fiori Systems
We mainly have three tier architecture for any System.

1. Presentation Layer

2. Application Layer (ABAP System)

3. Database Layer ( HANA )

Introduction
1

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
1. In our Presentation Layer { Earlier we used to do dialog programming on GUI i.e.
Module Pool ECC } but now we are using Fiori Apps on the Browser.

2. Earlier our Application Layer was ECC system where we use to do Screen/Dialog
Programming but now we are switching to WebServer services to expose data to Fiori
apps like CDS, AMDP, OData etc.

To enable these services we require a component called GW_FND which is only


available from Netweaver 740 systems.

SAP Netweaver is the runtime environment to execute the ABAP programs.

Introduction 2

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
3. Earlier we use to use Oracle, MSSQL, etc. as our Database layer but now we are
switching towards HANA Database.

2. How our Fiori App will communicate with our


local SAP Server
In the Frontend we will have our Fiori App and it will run on the browser, but browser only
understands the HTTP or HTTPS requests.
So, We will send a http request to our SAP system where there will be our OData Service
which is connected with variety of classes where we will write our logic which interact with
the database.

Introduction 3

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
We can expose our existing ERP data to the browser via HTTP or HTTPS using OData
services.

3. Responsibility of SAP Developers


Backend/ABAP Developers are responsible for Building OData Services using ABAP
Programming language.

For building OData Services we need basics of Object Oriented Programming language.

Frontend Developers are responsible for building Fiori Apps and consuming OData services
in the Fiori Application.
Or you can be SAP Full stack Developer and perform both kind of work.

4. Introduction to OData
OData stands for Open Data Protocol.

It was initially developed by a company called OASIS later acquired by Microsoft.

Microsoft made this open source i.e. why any body can use it.

OData is a protocol ( protocol means rules ) given by Microsoft to develop REST Service (
Representational State Transfer ) so that we can expose our data on internet using http or
https.

To build OData we can use any of the below programming language

.NET

Java

Python

Node.js

ABAP

Fiori App only and only talk to OData service , it do not care about the programming
language which has been used to develop the OData.

Introduction 4

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
In this training we will learn how to build our OData Service using ABAP programming
language.

5. Important T-Codes for OData


1. SEGW :- Service Gateway Builder

2. /n/IWFND/MAINT_SERVICE :- To register and view services

3. /n/IWFND/ERROR_LOG - Error Log

4. /n/IWFND/GW_CLIENT - Gateway Client - To Test Services locally in SAP System

5. SICF :- Check the entry of the registered service

6. SE24 :- Class Builder

7. SE37 :- Function Builder

8. SE38 :- Reports

9. SE80 :- ABAP Workbench

10. ST22 :- Dumps

6. Adding Maintenance Service as a Favorite


We are often going to use IWFND/MAINT_SERVICE to view and maintain OData services,
so it is better to use it as a Favorites.

Right click on Favorites and go for insert transaction.

Introduction 5

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
And add the service.

7. Free Used Service Given by SAP


Step 1 :- Go for the Maintenance Service added above, { /n/IWFND/MAINT_SERVICE }.

Introduction 6

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Step 2 :- Click on the Filter button and check the service.

Press enter.

Introduction 7

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
This is already registered in our SAP System.

8. How to add this service if it is not available ?


Step 1 :- Click on the add service.

Step 2 :- In the System Alias give Local as we are using the Embedded System and then in
the External Service name we will use GWSAMPLE_BASIC.

Introduction 8

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Press enter, select the service and click on the Add Selected Services.

In the Package assignment click on the Local Object.

Press enter.

Step 3 :- Click on the back button and you will find the service name there.

Introduction 9

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
9. Testing our Service
Click on the Call Browser button and it will launch our service.

Introduction 10

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Click on the Call Browser.

It will ask for the credentials, so pass the credentials there and click on Sign in.

This is service

And this whole things is known as service document.

s4h2023.sapdemo.com:8023/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/?
$format=xml

Introduction 11

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
10. Important Points
1. Service Document

Service Document will tell us all the available end points which are basically known as
Entity Sets.

2. Entity Set
Entity Set is the end point to perform CRUD Operations.

3. Entity Type
Every Entity Set is made up of Entity Type

Introduction 12

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Entity Type is the blueprint or the skeleton or the structure of the Entity Set

Checking all the Properties of a Entity Type


We can use $metadat in the URL to check all the properties of a Entity Type.
http://s4h2023.sapdemo.com:8023/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/$metadata

Metadata will also tells us about all the Entity Sets and their relationships also.

Metadata is the complete information about the entities and the properties of the OData
service.

Introduction 13

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
󾠯
Properties of OData Services
1. Introduction
OData acts as a backend for Frontend Applications.

OData Services are mainly executed under SAP NetWeaver gateway component with
database operations ( Select, Insert, Delete, Update ).
SAP NetWeaver gateway support two formats mainly

1. XML format

2. JSON format ( preferred because it is a light weight format ).

ODATA services are reusable.

OData ABAP services will be developed under SEGW transaction code.

2. Properties of OData Services


Every OData service contains mainly 4 folders :-

1. Data Model

2. Service Implementation

Properties of OData Services 1

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
3. Runtime Artifacts

4. Service Maintenance

3. Data Model
1. Entity Type

It is an option to maintain the collection of fields with data type and length.

Entity Type is similar to structure in normal ABAP.

2. Entity
Entity is an option to hold a single record at a time.

Entity is similar to work area in normal ABAP.

3. Entity Set
Entity Set is an option to hold the collection of records.

Entity Set is similar to internal table in normal ABAP.

4. Association
Association is the relationship between two entity types.

5. Association Set

Properties of OData Services 2

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Association set is a relationship between two entity sets.

Note :-
Under single ODATA project we can have n number of entity type and entity sets.

4. Service Implementation
It mainly contains CRUD methods.

i.e. It will contain all the methods that will be responsible for performing CRUD
operations

Methods in Service Implementation (1)

SAP Ui5 / FIORI ODATA Services

Create ————————————> CREATE_ENTITY( )


-> Create
method

Bind element ———>>>>>>> GET_ENTITY( ) method -> Read Select Query (0 1)

Bind rows/bind items ——————>>>>>>>


-> Read Select Query (0/1/N)
GET_ENTITYSET( ) method
Update —————————>>>>>>> UPDATE_ENTITY( )
method ----------->> U Update Statement
Remove ———————>>>>> DELETE_ENTITY( )
method ----------> D Delete Statement

5. Runtime Artifacts
Runtime artifacts mainly contains runtime classes ( which are auto generated ).

Whenever you will click on generate button, then these custom classes will be generated on
the runtime automatically.

1. _MPC → Model Provider Class

Properties of OData Services 3

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
2. _MPC_EXT → Model Provider Extension Class 3.

_DPC → Data Provide Class 4. _DPC_EXT → Data

Provider Extension Class

5. _SRV → Registered Service

6. _MDL → Registered Model

6. Service Maintenance
Error Log :- It is used to trace / find out the error occurred during service execution.

Gateway Client :- Temporary screen to test ODATA service functionality.

Properties of OData Services 4

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
󾠰
Developing our First OData Service

1. Introduction
We can develop OData services in two ways :-

1. Using BAPI/RFC

2. Without Using BAPI/RFC

2. Developing OData Service Using BAPI


We will use BAPI_FLIGHT_GETLIST to create our OData Service.

Let’s suppose, we are giving AC ( Airline ) as input.

Output
We will get one output in FLIGHT_LIST.

Developing our First OData Service 1

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
3. Implementation
Step 1 :- Go to SEGW transaction code.

Step 2 :- Click on create button, a pop up screen will open, provide the necessary details.

Click on Okay button and our project will be created.

Developing our First OData Service 2

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Step 3 :- We have to create a entity type and entity set by importing fields from ABAP
structure.
Step 4 :- Right click on data model → Import → DDIC structure.

A pop up screen will appear.

Step 5 :- Provide the name of entity type and also give ABAP structure.

Also select the Create default Entity Set checkbox.

Developing our First OData Service 3

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Step 6 :- Click on Next button, All the fields of the structure will get available from which
we need to select our required fields.

Step 7 :- Click on Next → A pop up screen will appear where you need to select at least one
primary key.

Click on Finish.

Developing our First OData Service 4

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
We can see our Entity Type and Entity Set has been created.

4. Mapping OData with BAPI


Step 1 :- Open the Service Implementation folder, and you will be seeing here all the CRUD
methods.

Step 2 :- Right Click on the get Entity Set option and select Map to Data Source Option.

Developing our First OData Service 5

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
A pop up screen will appear.

Here, we need to pass type as Remote function call, i.e. RFC and in the Name
section we will pass the name of BAPI.

Step 3 :- Click on Okay button.

Developing our First OData Service 6

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Step 4 :- Here, We will drag and drop the fields from the BAPI.

Step 5 :- Now, Once mapping is done, We need to generate the runtime artifacts.

Click on the red circle button → It will generate the runtime artifacts.

Developing our First OData Service 7

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Click on Okay button and assign the package and transport request.

You can see our Runtime artifacts has been generated.

5. Registering the Server Under SAP NetWeaver


Gateway
Step 1 :- Open the Service Maintenance.

Step 2 :- Click on Register button and give system Alias as local.

Developing our First OData Service 8

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Click on Okay button and assign the package.

Press enter and assign the requests.

You must get a green status and now our OData service is developed completely.

6. Testing OData Service


Step 1 :- Click on SAP Gateway Client.

Developing our First OData Service 9

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Step 2 :- Click on Entity Sets and select the particular Entity Sets.

Step 3 :- Click on Execute button.

Developing our First OData Service 10

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
We can see, we are getting all the data in XML format.

Data in JSON format


Select JSON format from URI.

Developing our First OData Service 11

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
7. Filter Conditions in OData Service
Using Filter conditions, we can filter out the required data.
Suppose, I want to apply some filter conditions.

Syntax :- ?$filter = Airlineid eq ‘AC’.

Developing our First OData Service 12

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
󾠱
Performing CRUD Operations in
OData Services

CRUD stands for CREATE, READ, UPDATE and DELETE

These are the database operations which we can perform using OData services in SAP.

To perform these CRUD operations we use CRUD methods.

Various CRUD methods available in OData Services :-


We have mainly 5 CRUD methods available in ODATA Services :-

1. Create_Entity( ) Method :-
This method is mainly used for creating a record in the table.

It has two important parameters :-

IO_DATA_PROVIDER :- This will capture input record values from front end
application ( SAP/Ui5/Fiori ).
ER_ENTITY :- This will send output record values to front end app.

Performing CRUD Operations in OData Services 1

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
2. Update_Entity( ) Method :-
This method is similar to create entity as it contains the same parameters as are there in
create entity method.
Used mainly to update a existing record in the table.

3. Delete_Entity( ) Method :-
This method is used to delete a particular record from the table.

It has one important parameters :-

IT_KEY_TAB :- This will capture input key field value from front end application.

4. Get_Entity( ) Method :-
This method is used to fetch a single record from the database.

It contains two important parameters :-

IT_KEY_TAB :- This will capture input key field value from front end application.

ER_ENTITY :- This will send output record to front end applications.

5. Get_EntitySet( ) Method :-
This method is used to fetch out one or more than one record from table based on certain
filter conditions.
It contains mainly two parameters :-

IT_FILTER_SELECT_OPTIONS :- It will capture input field from the front end


application.
ET_ENTITYSET :- It will send output record to front end application.

Table which we will use for our Requirement :-

Performing CRUD Operations in OData Services 2

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Implementation :-
Step 1 :- Create a OData project in SEGW transaction code.

Step 2 :- Right click on Data model → Import → DDIC Structure and create entity type and
entity set.
Step 3 :- Click on generate button to generate the runtime artifacts.

Step 4 :- Just Go to DPC Extension class and redefine the below methods and follows the
below steps.

1. Create Entity Method :-

2. Update Entity Method :-

Performing CRUD Operations in OData Services 3


3. Delete Entity Method.

4. Get Entity Method :-

Performing CRUD Operations in OData Services 4

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
5. Get Entity Set :-

Testing the OData at Gateway Client :-


1. Get Entity Set :-

Performing CRUD Operations in OData Services 5

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
2. Get Entity Method :-

3. Create Entity Method :-


To test this method, you need to first execute the get entity

method. Then click on use as a request. Make necessary changes

in HTTP Request section. Select the POST radio button and click

on execute.

Performing CRUD Operations in OData Services 6

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
4. Update Entity :-
Select the Put radio button to update any entity in OData services .

5. Delete Entity :-

Performing CRUD Operations in OData Services 7

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Performing CRUD Operations in OData Services 8

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
󾠲
Data Model
1. Data Model

To build OData service we need some sample data.

We will be using EPM( Enterprise Procurement Model) Data model.

It is a demo data set provided in SAP.

SAP gives us some Free BAPI for Sample Data.

BAPI is just a function ( a piece or set of code ) which is ready made and we can use it.

It’s like a function which we can use to get data out.

BAPI names for EPM model will start with

Data Model 1

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
BAPI_EPM_*

We can check in transaction SE37.

2. following BAPIs
1. for Business Partner

BAPI_EPM_BP_CREATE

BAPI_EPM_BP_GET_LIST

BAPI_EPM_BP_GET_DETAILS

BAPI_EPM_BP_CHANGE

BAPI_EPM_BP_DELETE

2. for Products
BAPI_EPM_PRODUCT_GET_DETAILS

BAPI_EPM_PRODUCT_GET_LIST

BAPI_EPM_PRODUCT_CHANGE

BAPI_EPM_PRODUCT_CREATE

BAPI_EPM_PRODUCT_DELETE

Note

All of them together are known as CRUD operations.

Data Model 2

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
󾠳
Implementing OData Service for
Our Project {GET}
1. Defining Entity and Entity Set for Products

Step 1 :- Go to SEGW and create a OData project for our Application.

Implementing OData Service for Our Project GET 1

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Click on save and assign the TR.

Step 2 :- Right Click on the Data Model and give a entity name and the structure for our
data.

Step 2 :- Click on Next and select the fields that you want to see.

Implementing OData Service for Our Project GET 2

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Step 3 Click on next and select the primary key and click on the finish button.

Implementing OData Service for Our Project GET 3

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Step 4 :- Now go to the properties and select the create, update, nullable, filtering for the
columns.

Click on save, then click on ProductSet and allow the creation, update, deletion etc.

Implementing OData Service for Our Project GET 4

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Step 5 :- Click on Generate button to generate all the runtime classes which are mandatory
for our system.

Note
Write all the manual logic in the MPC_EXT class and DPC_EXT class, because they
are only generated once.

2. Registering our Service


Step 1 :- Go to the Service Maintenance Folder → Click on Add Service and Pass local for
our Embedded System.

Implementing OData Service for Our Project GET 5

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Assign the package and transport request and our service registration is done.

3. Implementing Get_EntitySet method of


Product
Step 1 :- Go to the DPC_EXT class and redefine the get entity set method.

Step 2 :- We will append the initial line to et_entityset parameter.

Output

Implementing OData Service for Our Project GET 6

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Step 3 :- We will create a internal table for BAPI_EPM_PRODUCT_HEADER structure.

DATA  LT_BAPI_PRODUCTS TYPE TABLE OF BAPI_EPM_PRODUCT_HEADER.

Step 4 :- We will use the BAPI BAPI_EPM_PRODUCT_GET_LIST to get all the data from
the BAPI.

CALL FUNCTION 'BAPI_EPM_PRODUCT_GET_LIST'


* EXPORTING
* MAX_ROWS =

Implementing OData Service for Our Project GET 7

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
TABLES
HEADERDATA  LT_BAPI_PRODUCTS
* SELPARAMPRODUCTID =
* SELPARAMSUPPLIERNAMES =
* SELPARAMCATEGORIES =
* RETURN =
.

Step 5 :- Then we will pass the data from internal to exporting parameter.

ET_ENTITYSET  CORRESPONDING # LT_BAPI_PRODUCTS .

Implementing OData Service for Our Project GET 8

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Output

Implementing OData Service for Our Project GET 9

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
4. Implementing $top and $skip in Get Entity Set
Method
At this moment, if you will go and check &$top=1, then it will result you all the values.

We have a IS_PAGING parameter which receives the input given $top and $skip and
based on that we can implement our logic.

Step 1 :- We will create there variables, for top and skip and then for total also.

DATA  LV_TOP TYPE i,


LV_SKIP TYPE i,
LV_TOTAL TYPE i.

Implementing OData Service for Our Project GET 10

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Step 2 :- Then we will pass the paging parameters into it.

LV_TOP  IS_PAGINGTOP.
LV_SKIP  IS_PAGINGSKIP.
LV_TOTAL  LV_TOP  LV_SKIP.

Step 3 :- Now for our BAPI, we will define a importing parameters for us and we will pass
our LV_TOTAL into that parameter.

DATA  LV_MAX_ROWS TYPE BAPI_EPM_MAX_ROWS.


LV_MAX_ROWSBAPIMAXROW  LV_TOTAL.

Pass this variable into the BAPI parameter.

Implementing OData Service for Our Project GET 11

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Step 4 :- We will declare a work area for our ET_ENTITYSET parameter.

DATA  LS_ENTITY LIKE LINE OF ET_ENTITYSET.

Step 5 :- Now, we will go for a check before passing the data to the ET_ENTITYSET
parameter.

IF LV_TOTAL  0.
LOOP AT LT_BAPI_PRODUCTS into data(ls_BAPI_PRODUCTS FROM LV_S
MOVECORRESPONDING LS_BAPI_PRODUCTS to LS_ENTITY.
APPEND LS_ENTITY to ET_ENTITYSET.
ENDLOOP.
ELSE.
ET_ENTITYSET  CORRESPONDING # LT_BAPI_PRODUCTS .
ENDIF.

Implementing OData Service for Our Project GET 12

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Output

5. Implementing Filter in Get Entity Set Method


based on Category
In Our BAPI, we have a parameter SELPARAMCATEGORIES in which we can pass our
Filter condition.

Implementing OData Service for Our Project GET 13

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Step 1 :- We will define our internal table for category filter.

DATA  LT_CATEGORY TYPE TABLE OF BAPI_EPM_PRODUCT_CATEG_RANGE

Step 2 :- We will get the input request from frontend in IT_FILTER_SELECT_OPTIONS


parameter, so we will write logic for that.

First we will read the data coming from IT_FILTER_SELECT_OPTIONS.

READ TABLE IT_FILTER_SELECT_OPTIONS INTO data(LS_FILTER with key


IF SYSUBRC EQ 0.
LT_CATEGORY  CORRESPONDING # LS_FILTERSELECT_OPTIONS 

ENDIF.

Step 3 :- Then we will pass this into the parameter of BAPI.

Implementing OData Service for Our Project GET 14

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Output
Pass the URL in the browser.

Press enter and you will get the filtered categories based on the given input.

Implementing OData Service for Our Project GET 15

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
6. Implementing Get Entity Method
Step 1 :- Go to the DPC Extension class and redefine the Get Entity method.

Step 2 :- Read the input data given by user for the Employee Id.

DATA  LV_PRODUCT_ID TYPE BAPI_EPM_PRODUCT_ID.


READ TABLE IT_KEY_TAB INTO DATALS_KEY INDEX 1.
IF SYSUBRC EQ 0.
LV_PRODUCT_ID  LS_KEYVALUE.
ENDIF.

Implementing OData Service for Our Project GET 16

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Step 3 :- Define the importing parameter from the BAPI
BAPI_EPM_PRODUCT_GET_DETAIL and call the BAPI and pass the importing and
exporting parameter.

DATA  LS_HEADER TYPE BAPI_EPM_PRODUCT_HEADER.


CALL FUNCTION 'BAPI_EPM_PRODUCT_GET_DETAIL'
EXPORTING
PRODUCT_ID  LV_PRODUCT_ID
IMPORTING
HEADERDATA  LS_HEADER
* TABLES
* CONVERSION_FACTORS =
* RETURN =
.

Step 4 :- We will pass the received data to the ER_ENTITY.

Implementing OData Service for Our Project GET 17

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
MOVECORRESPONDING LS_HEADER TO ER_ENTITY.

Output

7. IF we are passing an empty value in the Get


Entity
IF we are passing an empty value into the Get Entity, then we will raise a exception from our
system.
Step 1 :- Check if the value of the products id is empty.

IF LV_PRODUCT_ID is INITIAL.

Implementing OData Service for Our Project GET 18

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
ENDIF.

Step 2 :- We will raise the exception if it is empty.

raise EXCEPTION type /IWBEP/CX_MGW_BUSI_EXCEPTION

Press enter and pass some text that you want to display.

RAISE EXCEPTION TYPE /IWBEP/CX_MGW_BUSI_EXCEPTION


EXPORTING
* TEXTID =
* PREVIOUS =
* MESSAGE_CONTAINER 
* HTTP_STATUS_CODE 
* HTTP_HEADER_PARAMETERS 
* SAP_NOTE_ID =
* MSG_CODE =
* EXCEPTION_CATEGORY =

Implementing OData Service for Our Project GET 19

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
* ENTITY_TYPE =
* MESSAGE =
MESSAGE_UNLIMITED  | Hello Amrit, this Product Id do not exist
* FILTER_PARAM =
* OPERATION_NO =
.

Now, we will get a exception message if I am not getting any input.

Output
Now, if we pass an empty string in get entity call then we will get this error
message.

Implementing OData Service for Our Project GET 20

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
8. Handling the Wrong Input in Get Entity
IF we will pass some wrong value to our BAPI, then BAPI will return us a message in its
return parameter.

Step 1 :- Define a internal table of type BAPIRET2 and pass it into the BAPI.

DATA  LT_RETURN TYPE TABLE OF BAPIRET2.

Step 2 :- We will check this internal table and if it is not empty we will raise the exception.

MEMO_CONTEXTGET_MESSAGE_CONTAINER ADD_MESSAGES_FROM
EXPORTING
IT_BAPI_MESSAGES  LT_RETURN .

RAISE EXCEPTION TYPE /IWBEP/CX_MGW_BUSI_EXCEPTION


EXPORTING
MESSAGE_CONTAINER  MEMO_CONTEXTGET_MESSAGE_CONTA

Implementing OData Service for Our Project GET 21

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Output

Implementing OData Service for Our Project GET 22

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
󾠴
POST, PUT, DELETE in ODATA
For POST request we are required to send the payload.

Payload
Payloads are typically the data that we are sending and mostly they are in JSON format.

We will go to the DPC Extension class and we will implement the POST request for the
product.
We will receive the data via IO_DATA_PROVIDER provider importing parameter and then
we will return the value in ER_ENTITY parameter.

1. Implementing Create Entity Method


Step 1 :- We will follow the below steps to Implement our Create Entity method.

*&Step 1  Take the input value


*&Step 2  Validate the data
*&Step 3  Preprocessing of data

POST, PUT, DELETE in ODATA 1

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
*&Step 4  Insert the data using BAPI
*&Step 5  Prepare the response and send back

Step 2 :- Take the input from the IO_DATA_PROVIDER.

DATA  LS_ENTITY TYPE ZCL_ZFINAL_ODATA_FIORI_MPCTS_PRODUCT.


IO_DATA_PROVIDERREAD_ENTRY_DATA
IMPORTING
ES_DATA  LS_ENTITY .

Step 3 :- Define the work area for BAPI input and store the input into work area.

DATA  LS_HEADER TYPE BAPI_EPM_PRODUCT_HEADER.


DATA  LT_RETURN TYPE TABLE OF BAPIRET2.

POST, PUT, DELETE in ODATA 2

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
MOVECORRESPONDING LS_ENTITY to LS_HEADER.
CALL FUNCTION 'BAPI_EPM_PRODUCT_CREATE'
EXPORTING
HEADERDATA  LS_HEADER " EPM Product header data of
* PERSIST_TO_DB  ABAP_TRUE " Flag: Save data to DB (yes/no)
TABLES
* CONVERSION_FACTORS  " EPM Product conversion factor da
RETURN  LT_RETURN " Return Parameter
.

Step 4 :- We will check for the exception and we will pass the return of BAPI to exception.

IF LT_RETURN is NOT INITIAL.


me→mo_context→get_message_container( )→add_messages_from_bapi(
EXPORTING
it_bapi_messages = lt_return ).

raise EXCEPTION type /IWBEP/CX_MGW_BUSI_EXCEPTION


EXPORTING
MESSAGE_CONTAINER  me→mo_context→get_message_container( ).

ENDIF.

POST, PUT, DELETE in ODATA 3

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Step 5 :- Now we will do the move corresponding to pass the data to final ER_ENTITY
output.

MOVECORRESPONDING LS_ENTITY to ER_ENTITY.

Step 6 :- Now if we will try to do the POST operation, we will get a error, so to resolve that
we are required to pass a unit of measure also into the BAPI.

LS_HEADERMEASURE_UNIT  'EA'.

POST, PUT, DELETE in ODATA 4

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Now our POST operation is ready we can directly use it.

method PRODUCTSET_CREATE_ENTITY.

*&Step 1  Take the input value


DATA  LS_ENTITY TYPE ZCL_ZFINAL_ODATA_FIORI_MPCTS_PRODUCT
IO_DATA_PROVIDERREAD_ENTRY_DATA
IMPORTING
ES_DATA  LS_ENTITY .
*&Step 2  Validate the data
*&Step 3  Preprocessing of data
DATA  LS_HEADER TYPE BAPI_EPM_PRODUCT_HEADER.
DATA  LT_RETURN TYPE TABLE OF BAPIRET2.
MOVECORRESPONDING LS_ENTITY to LS_HEADER.
LS_HEADERMEASURE_UNIT  'EA'.
CALL FUNCTION 'BAPI_EPM_PRODUCT_CREATE'
EXPORTING
HEADERDATA  LS_HEADER " EPM Product header data
* PERSIST_TO_DB  ABAP_TRUE " Flag: Save data to DB (yes/no
TABLES
* CONVERSION_FACTORS  " EPM Product conversion facto
RETURN  LT_RETURN " Return Parameter
.
IF LT_RETURN is NOT INITIAL.
me→mo_context→get_message_container( )→add_messages_from_ba
EXPORTING
it_bapi_messages = lt_return ).

POST, PUT, DELETE in ODATA 5

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
raise EXCEPTION type /IWBEP/CX_MGW_BUSI_EXCEPTION
EXPORTING
MESSAGE_CONTAINER  me→mo_context→get_message_container(

ENDIF.

MOVECORRESPONDING LS_ENTITY to ER_ENTITY.

endmethod.

Testing of Service from POSTMAN


We will test our service from Postman.

2. UPDATE Entity Method Implementation

POST, PUT, DELETE in ODATA 6

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Step 1 :- Redefine the Update Entity method.

Step 2 :- Define the work area and receive the input values from IO_DATA_PROVIDER
parameter.

DATA  LS_ENTITY TYPE ZCL_ZFINAL_ODATA_FIORI_MPCTS_PRODUCT.


DATA  LV_PRODUCT_ID TYPE BAPI_EPM_PRODUCT_ID.

READ TABLE IT_KEY_TAB INTO DATALS_KEY INDEX 1.


LV_PRODUCT_ID  LS_KEYVALUE.

IO_DATA_PROVIDERREAD_ENTRY_DATA
IMPORTING
ES_DATA  LS_ENTITY .

Step 3 :- Then we will define the importing parameter for our BAPI and we will pass its
value.

DATA  LS_HEADER TYPE BAPI_EPM_PRODUCT_HEADER,


LS_HEADER_X TYPE BAPI_EPM_PRODUCT_HEADERX.

POST, PUT, DELETE in ODATA 7

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
MOVECORRESPONDING LS_ENTITY to LS_HEADER.

Step 4 :- Then we will call BAPI.

LS_HEADER_XNAME  ABAP_TRUE.
LS_HEADER_XDESCRIPTION  ABAP_TRUE.
LS_HEADER_XPRICE  ABAP_TRUE.
LS_HEADER_XCURRENCY_CODE  ABAP_TRUE.
CALL FUNCTION 'BAPI_EPM_PRODUCT_CHANGE'
EXPORTING
PRODUCT_ID  LV_PRODUCT_ID " EPM Product Id
HEADERDATA  LS_HEADER " EPM Product header data of
HEADERDATAX  LS_HEADER_X " EPM Product header mod
* PERSIST_TO_DB  ABAP_TRUE " Flag: Save data to DB (yes/no)
* TABLES
* CONVERSION_FACTORS  " EPM Product conversion factor d
* CONVERSION_FACTORSX  " EPM Prod. conv. fact. modif. data
* RETURN = " Return Parameter
.

POST, PUT, DELETE in ODATA 8

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
Step 5 :- Define the return parameter for BAPI.

Step 6 :- We will check exception and we will raise it.

IF LT_RETURN is NOT INITIAL.


MEMO_CONTEXTGET_MESSAGE_CONTAINER ADD_MESSAGES_FRO
EXPORTING
IT_BAPI_MESSAGES  LT_RETURN .

RAISE EXCEPTION TYPE /IWBEP/CX_MGW_BUSI_EXCEPTION


EXPORTING
MESSAGE_CONTAINER  MEMO_CONTEXTGET_MESSAGE_CONTA
.

POST, PUT, DELETE in ODATA 9

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
ENDIF.

Step 7 :- IF everything is fine we will display result from ER_ENTITY.

MOVECORRESPONDING LS_ENTITY to ER_ENTITY.

method PRODUCTSET_UPDATE_ENTITY.

DATA  LS_ENTITY TYPE ZCL_ZFINAL_ODATA_FIORI_MPCTS_PRODUCT.


DATA  LV_PRODUCT_ID TYPE BAPI_EPM_PRODUCT_ID.

READ TABLE IT_KEY_TAB INTO DATALS_KEY INDEX 1.

POST, PUT, DELETE in ODATA 10

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
LV_PRODUCT_ID  LS_KEYVALUE.

IO_DATA_PROVIDERREAD_ENTRY_DATA
IMPORTING
ES_DATA  LS_ENTITY .

DATA  LS_HEADER TYPE BAPI_EPM_PRODUCT_HEADER,


LS_HEADER_X TYPE BAPI_EPM_PRODUCT_HEADERX.

MOVECORRESPONDING LS_ENTITY to LS_HEADER.

LS_HEADER_XPRODUCT_ID  LV_PRODUCT_ID.
LS_HEADER_XNAME  ABAP_TRUE.
LS_HEADER_XDESCRIPTION  ABAP_TRUE.
LS_HEADER_XPRICE  ABAP_TRUE.
LS_HEADER_XCURRENCY_CODE  ABAP_TRUE.
DATA  LT_RETURN TYPE TABLE OF BAPIRET2.
CALL FUNCTION 'BAPI_EPM_PRODUCT_CHANGE'
EXPORTING
PRODUCT_ID  LV_PRODUCT_ID " EPM Product Id
HEADERDATA  LS_HEADER " EPM Product header data of
HEADERDATAX  LS_HEADER_X " EPM Product header mod
* PERSIST_TO_DB  ABAP_TRUE " Flag: Save data to DB (yes/no)
TABLES
* CONVERSION_FACTORS  " EPM Product conversion factor d
* CONVERSION_FACTORSX  " EPM Prod. conv. fact. modif. data
RETURN  LT_RETURN " Return Parameter
.
IF LT_RETURN is NOT INITIAL.
MEMO_CONTEXTGET_MESSAGE_CONTAINER ADD_MESSAGES_FRO
EXPORTING
IT_BAPI_MESSAGES  LT_RETURN .

RAISE EXCEPTION TYPE /IWBEP/CX_MGW_BUSI_EXCEPTION


EXPORTING

POST, PUT, DELETE in ODATA 11

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
MESSAGE_CONTAINER  MEMO_CONTEXTGET_MESSAGE_CONTA
.

ENDIF.

MOVECORRESPONDING LS_ENTITY to ER_ENTITY.


endmethod.

Output

3. Implementing Delete Entity Method


method PRODUCTSET_DELETE_ENTITY.

DATA  LV_PROD_ID TYPE BAPI_EPM_PRODUCT_ID.


DATA  LT_RETURN TYPE TABLE OF BAPIRET2.
READ TABLE IT_KEY_TAB INTO DATALS_KEY INDEX 1.
LV_PROD_ID  LS_KEYVALUE.

CALL FUNCTION 'BAPI_EPM_PRODUCT_DELETE'


EXPORTING
PRODUCT_ID  LV_PROD_ID " EPM Product ID
* PERSIST_TO_DB  ABAP_TRUE " Flag: Save data to DB (yes/no)
TABLES
RETURN  LT_RETURN " Return Parameter
.

POST, PUT, DELETE in ODATA 12

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
IF LT_RETURN IS NOT INITIAL.
MEMO_CONTEXTGET_MESSAGE_CONTAINER ADD_MESSAGES_FROM_
EXPORTING
IT_BAPI_MESSAGES  LT_RETURN .
RAISE EXCEPTION TYPE /IWBEP/CX_MGW_BUSI_EXCEPTION
EXPORTING
MESSAGE_CONTAINER  MEMO_CONTEXTGET_MESSAGE_CONTAINE
.

ENDIF.
endmethod.

Output

POST, PUT, DELETE in ODATA 13

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944
POST, PUT, DELETE in ODATA 14

Amrit Raj (Chief Operations Officer) | Srijan Institute & Training Center | +919220601944

You might also like