Creación Servicio ODATA SAP
Creación Servicio ODATA SAP
Creación Servicio ODATA SAP
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.
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.
Now we are going to define structure of work area and internal table, Right click on Data model select
import and select DDIC structure .
Here give the details of structure and structure name as per below screen below. Select radio button
Entity type and click on check box entity set. fill ABAP structure as VBAK and click on next.
Now you will get the pop-up screen with VBAK table fields name. Select fields for your structure and
click on next.
Another window will appear where we must select the key field. tick on VBELN as key field and click on
finish. You may get warning message; it can be totally ignored.
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.
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 the details, and proceed further. These are also knowns as
runtime artifacts.
Step 2. Go to transaction code /IWFND/MAINT_SERVICE and click on push button - Add services.
Next screen will appear, give the alias name, and execute, Search for your project and 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.
Now click back and go to main screen of transaction /IWFND/MAINT_SERVICE and find your service.
Click on SAP Gateway Client.
A new screen will come, Execute the transaction, and check the response.
Status code 200 means that the OData service we created works well and now, we will write code to
get data.
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.
Now expand the method drop down and select method for GetEntitySet for Header data and right click
and select redefine.
Write below code in method. Save and activate all related objects for classes.
Similarly, Write the code for GetEntitySet for Item and activate.
Step -4: Go to transaction /IWFND/MAINT_SERVICE and find out you service, select your service and click
on load metadata.
Information message will pop up - Metadata has been loaded successfully. Now Click on SAP Gateway
Client.
Similarly, select entity set for item and execute. You will get data for item
That’s all. We have completed our Odata service creation with a Service Gateway 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.
SAP Gateway Based OData Service using SADL Framework –
Let’s go with the steps on how to create an OData service using the Service Adaptation Description
Language (SADL) framework and referencing SAP ABAP CDS views in SEGW Gateway Builder. Content is
taken from a blog written by Vishal Kumar.
Create an empty project in Service Gateway Builder using the T-code: SEGW. To create the Data Model,
we need to refer to Data Source. (CDS View in this case).
In the next screen, we can see all the elements of CDS entity and corresponding Associations.
Select all the elements and proceed further. (We can select only the fields which are relevant for as per
Business Need and we always have the option to edit that later).
After completing this step all the Entity, Entity Sets, Association & corresponding Navigation is
automatically generated in the Gateway Project.
Now, generate the service. After generating Register and Maintain the service. Test the OData service in
Gateway Client (/IWFND/GW_CLIENT).
We can see all the Entity and corresponding Association in the Metadata Information.
We can execute the service with different Entities to see the results.
Publishing CDS View as OData Service –
This method is also referred as annotation-based approach using CDS views. Content is taken from a
blog written by Jagdish Patil.
Create a CDS View with the below code. The annotation @OData.publish: true is used to publish the
CDS as OData Service.
@AbapCatalog.sqlViewName: 'ZJP_SO_DATA_N'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Sales Order Data CDS'
@OData.publish: true
define view ZJP_SO_NEW
as select from vbak as header
association [1..*] to vbap as _item
on header.vbeln = _item.vbeln
{
key vbeln as Vbeln,
erdat as Erdat,
erzet as Erzet,
ernam as Ernam,
auart as Auart,
netwr as Netwr,
waerk as Waerk,
vkorg as Vkorg,
vtweg as Vtweg,
spart as Spart,
kunnr as Kunnr,
_item
}
Activate the CDS View created. Post Activation, a yellow warning symbol appears beside the annotation
@OData.publish: true. Hover the cursor over the line to get a pop up like below.
The Service Name appears in the pop-up and the warning says that the Service is not active. The service
name will be the CDS View name followed by _CDS.
Register the service ZJP_SO_NEW_CDS using transaction /IWFND/MAINT_SERVICE. Use the add service
button.
And the service is registered. Now, Test the Service. Use Filter to get the registered service. Start from
the transaction /IWFND/MAINT_SERVICE. Click on the Filter button.
Use the exact service name or something like ZJP* to filter the services. Click on the right service and
use SAP Gateway Client to test the service.
This service has 2 sets, ZJP_SO_NEW and VBAP. VBAP can be called directly or with Association.
URIs to test
/sap/opu/odata/sap/ZJP_SO_NEW_CDS/ZJP_SO_NEW?$format=json
/sap/opu/odata/sap/ZJP_SO_NEW_CDS/ZJP_SO_NEW(‘1’)?$format=json
/sap/opu/odata/sap/ZJP_SO_NEW_CDS/ZJP_SO_NEW(‘1’)/to_item?$format=json
/sap/opu/odata/sap/ZJP_SO_NEW_CDS/VBAP?$format=json
/sap/opu/odata/sap/ZJP_SO_NEW_CDS/ZJP_SO_NEW(‘1’)?$expand=to_item&$format=json
To know how to develop an OData service based on SAP RAP, follow the series of blogs by Jagdish Patil.
To know how to develop an OData service based on SAP CAPM, check out this video from Anubhav
Oberoy.