How to create OData Service using RFC or BAPI


Dear SAPLearners, in this tutorial we will learn how to create OData service using RFC or BAPI in SAP Netweaver Gateway.

When it comes to exposing the data to outside world this is easily done by OData service.In SAP we have numerous RFC’s and BAPI’s available in several functional areas to get the data.

In this blog post we will use RFC/BAPI to build the OData service. Before building the service first identify the BAPI/RFC you need. You can use transaction code “BAPI” or “SE37” to identify the BAPI/RFC function modules.

In this example we will use the EPM data and BAPI “BAPI_EPM_PRODUCT_GET_LIST” to retrieve the list of materials in SAP.

EPM data is the well know data model like FLIGHT data model available in any SAP system for demo purpose. You can generate the data by using the transaction “SEPM_DG”.

For easy understanding I have divided this tutorial into 2 parts. In the part-1 we will create service definition with Entities and test the service by registration. In the part-2 we will map the service to the BAPI to get the data. So lets get started and build the service.

1. Go to Service Gateway builder and the transaction to it is SEGW.

SEGW - Create a new Project

2. In the create project window, enter the Project name and Description. In the Attributes section leave with defaults and provide then choose the package name. Hit OK button to proceed further.

SEGW - Create a Project

3. After entering the OK button, you can see the project got created in Gateway service builder. All the nodes in the project are empty. Our next step will be creating the Entity Types and Entity Sets required for the OData service.

SEGW - Project got created

4. We are using BAPI “BAPI_EPM_PRODUCT_GET_LIST” to get the list of products, so here we need the Entity Type structure which is similar to the structure BAPI_EPM_PRODUCT_HEADER in the BAPI.
To create Entity Type :   right click on Data Model → Import → RFC/BOR Interface.

SEGW - Create an Entity Type

5. In the Create Entity Type window, enter the Entity Type Name.

  • Under Data Source Attributes section choose Type as : Remote Function Call and Name as the BAPI name – BAPI_EPM_PRODUCT_GET_LIST.
  • Under Target System section – ♦ choose “Local” if your deployment is Embedded ♦ choose “Remote” if your deployment is Hub.
  • Select the check box Create Default Entity Set, if you want the Entity Set to be create automatically.

SEGW - Entity Type

6. Click on Next to proceed to step 2 of Entity Creation wizard. In this step choose the fields you want to be displayed in the service. Here we have selected PRODUCT_ID, CATEGORY, NAME, DESCRIPTION, SUPPLIER_NAME, PRICE and CURRENCY_CODE fields from the structure HEADERDATA[].

SEGW - Choose Output fields

7. Hit Next button to navigate the step-3. In this step we need to choose the Key Field in the Entity Type which is mandatory. Choose ProductId is the key field by selecting the check box in the column “Is Key”. Hit Finish button to complete the Entity Type creation process.

SEGW - Choose Key Field

8. Now we have created Entity Type – ProductList and Entity Type sets – ProductListSet.

SEGW - Entity Type and Entity Sets

9. Save and generate the service to create run-time artifacts.

SEGW - Service genereate successfully

10. By now we have modeled the service, out next step is to map the service to the BAPI to get the data. To do so go to and expand “Service Implementation” node. Expand the ProductListSet entity set , choose GetEntitySet(Query) and right click on it and then go to “Map to Data Source”.

SEGW - Map Data Source

11. In the Map to Data Source window, choose Local as Target System if your deployment is Embedded (or) Remote if your deployment is Hub.

SEGW - Provide BAPI Name

12. In the next step, you need map the BAPI fields to the service entity type fields. Hit Propose Mapping button to automatically the map the fields or you can manually drag drop the fields from the right to the column “Data Source Parameter“.

SEGW - Data Source fields mapping

13. Save and regenerate the service, by hitting generate button.

14. By this we have completed building the service, our next task is to register the service and test the service. We are going to discuss these steps here as i have explained in detail here OData Service Registration.

15. Test the service by using the transaction /IWFND/GW_CLIENT.

Gateway Client - Test the Service

So we have successfully created OData service using RFC/BAPI. Hope this tutorial help you.

Please feel free to comment and let us know your feedback. Subscribe for more updates

If you liked it, please share it! Thanks!

Comments are closed.