Exploring Diverse Approaches of OData Services creation in SAP
Introduction
OData (Open Data Protocol) is a standardized protocol for building and consuming RESTful APIs
Creating OData services in SAP offers various approaches to cater to different development scenarios and requirements. These methods provide flexibility and allow developers
In this article , we would be talking about below approaches.
1. SEGW : Manual Approach
Go to T-code SEGW and create new project
Create Entity
Enter Entity and Entity set name.
Expand Entity and double click on property to add field .
project should look like below.
Save project and generate service.
Runtime objects would get generated.
Add service through T-code /n/iwfnd/maint_service
Go to T-code /n/iwfnd/maint_service , select service and click on SAP Gateway client.
We can go to below screen via /n/iwfnd/gw_client as well.
2.SEGW : Import
We will create Odata project through DDIC table.
DDIC table .
Go to SEGW project , right click on data model > import > DDIC Structure
Give Entity name and DDIC structure.
select desired field and finish.
After save , project would look like below.
Generate runtime object
We can see there is another entity has been added (imported from DDIC ).
3. SEGW : SADL Approach
We will use below CDS to create OData service. We can leverage benefits of CDS annotations
Go to SEGW project , Right Click on data model >> Reference >> Data source.
Provide CDS name and proceed further.
Project would look like below.
Generate service and check service in /N/IWFND/GW_CLIENT. There is another entity set has been generated from CDS view.
4. SEGW : RFC
We can create OData service on RFC enabled Function module and make use of the FM functionality through service.
We have created a custom RFC FM which has importing parameter VBELN and returns VBELN,AUART and LIFSK .
Create SEGW project.
Right click on data model ,Import >>RFC/BOR Interface.
Provide entity name and RFC enabled FM to proceed.
Select required parameters.
Mark suitable field as key and finish.
Project would look like below.
Now we need to map the service to the FM to get the data. Expand Service implementation and right click on getEntity(Since we are reading data from FM) and click map data source .
Provide FM details.
Propose mapping ,framework will auto map the importing and exporting fields.
Recommended by LinkedIn
As of now we have generated design time objects , lets Generate runtime objects.
Since we have mapped the data source to GET_ENTITY method , framework has generated code accordingly. Lets check DPC_EXT class.
Next step is to register the service and test
Go to T-code /N/IWFND/MAINT_SERVICE
Service has been generated . OData is a complete framework , we can create and test OData service within SAP system itself .
We can go to SAP gateway system to test the service (/N/IWFND/GW_CLIENT).
We have pass VBELN through URI and service has executed FM and return the data.
5. Annotation Based
We can create Odata service directly from CDS view with the help of annotation 'Odata.publish:true' .
If we notice ADT is showing warning that service is not active.
Go to T-code /N/IWFND/MAINT_SERVICE and add the service .
Odata service is activated now.
Important URIs
A URL used by an OData service has at most three significant parts: the service root URL, resource path and query options. Additional URL constructs (such as a fragment) MAY be present in a URL used by an OData service; however, this specification applies no further meaning to such additional constructs.
/sap/opu/odata/sap/ZGW_PO_SRV/$metadata
/sap/opu/odata/sap/ZGW_PO_SRV/POHeaderSet(‘4500002012’).
/sap/opu/odata/sap/ZWM_ODATA_SRV/ZZCALIBRATE_JSON_Set(CMSASSET=’CMS456788879′,LAST_CAL_DATE=’20160923′,CAL_DUE_DATE=’20230923′)
/sap/opu/odata/sap/ZWM_ODATA_SRV/ZZCALIBRATE_JSON_Set?&$filter=CMSASSET eq ‘CMS45678887
/sap/opu/odata/sap/ZGW_PO_SRV/POHeaderSet(‘4500002013’)/Lifnr.
/sap/opu/odata/sap/ZGW_PO_SRV/POHeaderSet/$count
/sap/opu/odata/sap/ZGW_PO_SRV/POHeaderSet(‘4500002012’)/$count
/sap/opu/odata/sap/ZGW_PO_SRV/POHeaderSet?$select=Ernam,Bukrs,Ebeln.
/sap/opu/odata/sap/ZGW_PO_SRV/POItemSet?$select=Ebeln,Ebelp,Werks&$format=json
/sap/opu/odata/sap/ZGW_VIM_APP_SRV/DocDetailSet?&$filter=Xblnr eq ‘RON MILLS 2’
?$filter=Erdat gt datetime’2015-01-01T00:00:00’and Ekgrp eq ’17’and Werks eq ‘4030’
/sap/opu/odata/sap/ZGW_PREQ_SRV/PReqSet?$filter=Erdat gt datetime’2015-01-01T00:00:00’and Ekgrp eq ’17’and Werks eq ‘4030’
Association specifies the cardinality between Entity Types. When an Association is created, a Navigation Property of the Entity Type is also generated.
if we execute below query to get one data set , system will show us (link href ) that we can make use of navigation property as well.
it will show the code as well.
/sap/opu/odata/sap/ZGW_PO_SRV/POHeaderSet(‘4500002012’
<link href=POHeaderSet(‘4500002012’)/HeadtoItemNav)
/sap/opu/odata/sap/ZGW_PO_SRV/POHeaderSet(‘4500001729’)?$expand=HeadToItemNav
whereas below URL will fetch only item details
/sap/opu/odata/sap/ZGW_PO_SRV/POHeaderSet(‘4500001729’)/HeadToItemNav
Conclusion and further resources
This guide has given an overview of OData services and walked you through the step-by-step process of creating a service using SAP.
If you're looking for more information, check out the official SAP documentation on OData service creation, the OData official website, and the OData community resources. Thanks for reading!
Full Stack Developer at Alterno.io & Co-founder/CTO at CivilPlanner.co
9moGood overview of OData service creation! This post neatly sums up the complexities involved in a very digestible format.
SAP/SAP BTP/HANA Architect, Integration Analyst, SAP Build Work Zone, SAP Cloud Integration -CPI / SAP PI, Sr. ABAP-ABAP Restful Developer, Fiori-SAPUI5/Web Dynpro, CDS, ODATA - JAVA Sr. Full-Stack Backend Senior
1yClean
Certified SAP ABAP on HANA & ODATA Technical Consultant with 6 Plus Experience at HCLTECH || Ex-Yash Technologies || Ex-Capgemini || Ex-Wipro.
1yVery useful.. clear explanation 👍