Introduction:
In this Blog, I want to walk through the detailed steps to create OData Web API Service for a standard storage Bin table:/SCWM/LAGP with low-code/no-code.
Target Audience and prerequisites:
- ABAP developers who are new to RAP
- Basic knowledge of CDS Views and ABAP Development Tools (ADT)
- System used: SAP S/4HANA (On-Premise)
Step 1. Create an ABAP package.
This ABAP package will contain all the artefacts related to the OData Web API Service.
In ADT, go to the Project Explorer, right-click on the System Instance, and select New > ABAP Package from the context menu.
Maintain the required information, then Click Next >
Select a transport request and click Finish
Add the package created: “ZEWM_RAP_ST_BIN_DATA” to the favorite packages, using select Favorite Packages > ADD Package from the context menu.
The package adds Under Favorite Packages:
Step 2. Add Standard table to the favorite objects
(no need to add if the table is already available in the Favorite Objects, just search for it).
Right-click on Favorite Objects and select Add Object from the context menu
Search for standard table :/SCWM/LAGP and click OK
The Table /SCWM/LAGP adds under Favorite Objects
Step 3. Create your OData v4 based WEB API service with the built-in ADT generator.
Right-click the standard database table /SCWM/LAGP under favorite objects and select Generate ABAP Repository Objects from the context menu.
Select OData Web API Service and click Next >.
Provide the ABAP Package and click Next >.
Maintain the required information on the Configure Generator dialog to provide the name of your data model, Behavior, Service Definition etc.
and click Next > to generate them.
Select a transport request and click Finish
Go to the Project Explorer, select your package refresh it by pressing F5, and check all generated ABAP repository objects
The service binding is not generated due to inactive service definition, The conversion errors in the entity LC_LAGP00 are the cause for the inactive service definition.
In SAP RAP (ABAP RESTful Application Programming Model), OData services block most standard DDIC conversion exists including ALPHA routines because they can cause runtime and formatting errors.
To resolve this, use a custom CDS type cast in your Core Data Services (CDS) view. After removing the errors in CDS View, activate the service definition and create the service Binding,
Right click the service definition ‘ZAPI_LAGP_O4’ and select New Service Binding. Provide the Service Binding details and click Next >
Select a transport request and click FinishSelect the service Binding and Activate it.
Right Click the CDS view and Select data Preview to display the filled database entries
Step 4. Publish the local service endpoint of your service binding
Open your service binding ‘ZSB_API_LAGP_O4 and click Publish.
A local publish failure for OData V4 service bindings in ADT typically stems from backend gateway synchronization gaps, transport/client restrictions or an ADT/BTP Trial environment regression bug. You can resolve this by manually publishing via SAP Gateway or switching protocols.
In case of above error, click on the Menu button Run ABAP Development Object as ABAP Application in SAPGUI or press Alt+F8.
Type /iwfnd/v4_admin as a search string and double-click on the entry /IWFND/V4_ADMIN (Transaction).
Click the button Publish Service Groups to get a list of service groups that can be published
Enter following values to search for the service group of your service and press the button Get Service Groups:
- System Alias: LOCAL
- Service Group ID: ZSB_API_LAGP_O4
Select the entry ZSB_API_LAGP_O4 from the list and press the button: Publish Service Groups. Confirm the success message and press Enter. The service will be published
Once the service is published, we get the service URL.
Add your SAP Host and Port (http://<host>:<port>) to the Service URL (/sap/opu/odata4/sap/zsb_api_lagp_o4/srvd_a2x/sap/zapi_lagp_o4/0001/) to test the URL.
we can use the URL in below ways:
1. Paste the URL into a tool like Postman or your web browser to view the service metadata or data feeds.
2. Connect the URL to SAP Business Application Studio or SAP UI5 projects to build user interfaces.
3. Use the URL in non-SAP software or custom apps that need your data.
Conclusion:We learned how to create OData Web API Service using the Generate ABAP Repository Objects wizard in ABAP Development Tools (ADT) to generate the entire RAP stack i.e., CDS Data Definitions, Behavior Definitions, Service Definition, and Service Binding automatically.