Wednesday 14 July 2021

A Step by Step process to create Odata services in SAP / SAP HANA system

In this blog post, I am going to tell you step by step process to create Odata services for SAP /SAP HANA system and how to test it.

I tried to explain the whole process in 4 steps.

Step 1. Go to transaction code – SEGW.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Preparation

Click on Icon Create. A pop window will appear, Fill the details as per below mention in screen shot and click on check icon or enter.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Preparation

Below screen will appear where you can see below folder in project. In Folder data model, we can see three sub folders. Entity Type – it acts as work area, Entity Sets -It act as internal table and associations.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Preparation

Now we are going to define structure of work area and internal table, Right click on Data model select import and select DDIC structure.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Preparation

Here give the details of structure and structure name as per below screen below.

Select radio button Entity type and and click on check box entity set. fill ABAP structure as VBAK and click on next

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Preparation

Now you will get the pop up screen with VBAK table fields name. Select fields for your structure and click on next.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Preparation
project5

Other window will appear where we have to select the key field. tick on Vbeln as key field and click on finish. You may get warning message, it can be totally ignored.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Preparation

Now expand folder entity type and fill the below parameters in properties, Please don’t tick Null check box for VBELN as it is key field.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Preparation

Similarly Create Structure for SD Item following same steps

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Preparation

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Preparation

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Preparation

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Preparation

click on Save button at the top of menu bar

Now click on generate Icon, A pop up window will appear with class details, click on tick icon and proceed further. It will ask for package, give details and proceed further. These are also knowns as runtime artifacts.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Preparation

Step 2. Go to transaction code /IWFND/MAINT_SERVICE.

Click on push button Add services.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Preparation

Next screen will appear, give the alias name and execute, Search you for your project.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Preparation

Now double click on your project name. A pop up window will appear, enter the package details and click on tick icon. An Information message will be shown where it will confirm about the service is created and metadata loaded successfully

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Preparation

Now click back and go to main screen of transaction /IWFND/MAINT_SERVICE and find your service.

Click on SAP Gateway Client

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Preparation

A new screen will come, Execute the transaction and check the response.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Preparation

Now we will write code to get data.

Step 3. Go to transaction code SEGW and expand folder service Implementation.

Under service implementation – Expand SDheaderSet. you will find different options. Right click on GetEntitySet and select GO to ABAP work Bench. It will redirect to the class

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Preparation

Now expand the method drop down and select method for GetEntitySet for Header data and right click and select redefine.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Preparation

Write below code in method. Save and activate all related objects for classes.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Preparation

Similarly, Write code for GetEntitySet for Item and activate.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Preparation

Step 4. Go to transaction /IWFND/MAINT_SERVICE and find out you service, select your service and click on load metadata.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Preparation

Information message will pop up – Metadata has been loaded successfully.

Now Click on SAP Gateway Client.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Preparation

Now Click on Entity set.

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Preparation

Select entity for header and enter

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Preparation

Click and execute and you will get the header data in response

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Preparation

Similarly, Select entity set for item and execute. You will get data for item

SAP ABAP Tutorial and Material, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Preparation

Here, We had completed our Odata service creation with a Service Builder Project with two entities and two entity-sets. We have generated the runtime artifacts and registered and activated our OData service. We had redefined methods of header and item entity set, load metadata and test the entity set with for test data.

Source: sap.com

No comments:

Post a Comment