Earlier While creating an OData service, I have gone through multiple blogs which has few steps to create Odata Service that helpIed me to create the service. But for every term, I needed to go and search for the particular term to understand what actually they do.

So here in this blog, I am going to tell step by step process of creating an OData service with the explanation of the term used in the creation for the better understanding and testing the service in the SAP Gateway Client.

What is ODATA: SAP OData is a standard Web protocol used for querying and updating data present in SAP using ABAP, applying and building on Web technologies such as HTTP to provide access to information from a variety of external applications, platforms and devices. In SAP, we use SEGW transaction code to create an OData Service.

I tried to explain the process in few steps.

 

Step 1: Go to transaction code: SEGW.

 

Step 2: Click on ‘New Project’ icon, a new pop-up screen will appear, fill all the details and save either locally or give package where you want your project to be saved.

Project name should start with ‘Y’ or ‘Z’.

 

We can see a project created with folders.

Step 3: Right click on the data model, select import and select DDIC structure. Now we are going to define structure of work area and internal tables.

Either we can import tables through DDIC structure or can create Entity Type manually.

  1. Importing through DDIC structure.

 

A new pop screen will appear, fill all the details of structure and structure name.

Click on the ‘Entity Type’ radio button, check the checkbox for default ‘Entity Set’ and then ‘Next’.

 

Now you will get a screen with all ‘VBAK’ table fields, select fields for your structure and click on ‘Next’.

 

Another window will appear, take ‘VBELN‘ as a key field for your structure and then click on ‘Finish’.

 

We will get a message for successfully creating entity type.

These warnings can be ignored.

 

Dropdown entity type, we can see the entity type with the properties automatically.

 

  1. Creating entity type manually.

Right click on the ‘Entity Type’ and select ‘Create’.

 

We will get a pop-screen, enter the entity type name and check the checkbox for entity set name. You will get entity set name automatically, then click on ‘Tick’.

 

After this, we can see that our entity type is created, click on the ‘Properties’ and then insert rows as you want for your structure and make key field as well.

 

Similarly Create Structure for SD Item following the same steps.

 

 

 

Click on the ‘Save’ icon from the top.

 

Step 4: Then click on ‘Generate Runtime objects’, a pop-up window will appear with class details, click on tick icon proceed. Give packages details or can save locally and click on ‘Tick’.

 

All the MPC and DPC classes will be generated.

 

Step 5: Expand ‘Service Implementation’, expand “SaleHeaderSet’, right click on ‘GetEntitySet(Query)’ and then Go to ABAP Workbench.

 

Class builder window will appear, dropdown ‘Methods ‘. In ‘Inherited Methods’, right click on ‘SALEHEARDERSET_GET_ENTITY’ and select ‘Redefine’.

This will redefine the Get entity set.

 

Step 6: Redefined method ‘SALEHEARDERSET_GET_ENTITYSET’, we can start coding.

 

Write code, save and activate in ‘SALESHEADERSET_GET_ENTITYSET’.

 

Similarly, write code, save and activate for ‘SDITEMSET_GET_ENTITYSET’.

 

Step 7: Go to transaction code /IWFND/MAINT_SERVICE.

Step 8: Click on ‘Add Service’.

 

Put ‘System Alias’ name as ‘LOCAL’ and press enter, you will a see a list of projects. Choose your project.

 

Double click on your Project name, a pop-up screen will come, enter ‘package assignment’ and click on ‘Tick’.

 

An information will pop-up talking about the creation of service.

 

Then go back to the main screen of transaction /IWFND/MAINT_SERVICE, find your service and click on ‘SAP Gateway Client’.

 

A new screen will appear with the URI of your project.

 

Click on EntitySet and select EntitySet and then execute.

 

After executing, getting the details of header data.

 

Similarly, you will get the details of items data.

 

After executing the service in SAP Gateway Client, if we received status_code as ‘200‘, our service working fine other than 200 then we need to check the error logs from there we can see why our service is giving error.

So here we have completed the creation of OData Service with two entity types and entity sets. Generated the runtime artifacts, loaded metadata, created URI and tested both the entities.

Sara Sampaio

Sara Sampaio

Author Since: March 10, 2022

5 1 vote
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x