SAP OData Services: How They Work and How to Build One

Vikram Sanap · 31 January 2025 · 3 min read

How SAP OData services work, how to read one from its URL with $filter and $expand, and how to build one with SEGW or with a RAP service definition and binding.

OData (Open Data Protocol) is the REST-based standard SAP uses to expose business data over HTTP. Every SAP Fiori app talks to the back end through an OData service, and so do many mobile apps and outside systems, which makes reading and building OData services a core ABAP skill.

OData in five points

• An open standard maintained by OASIS and approved by ISO/IEC; Microsoft created the first version.

• Data is organized in entity sets (all sales orders) made of entities (one sales order) with properties and navigation to related entities.

• Plain HTTP methods do the CRUD work: GET reads, POST creates, PUT or PATCH updates, DELETE deletes.

• Every service has a service document (its root URL, listing the entity sets) and a metadata document ( $metadata , describing every entity, key and property).

• Answers come as JSON; SAP's OData V2 services can also answer in XML (Atom).

Read a service from its URL

OData V2 services in SAP Gateway live under /sap/opu/odata/sap/ . Reading is a plain GET , so you can explore a service in a browser or in the Gateway Client ( /IWFND/GW_CLIENT ):

/sap/opu/odata/sap/ZSALESORDER_SRV/$metadata

/sap/opu/odata/sap/ZSALESORDER_SRV/SalesOrderSet?$top=10&$format=json

/sap/opu/odata/sap/ZSALESORDER_SRV/SalesOrderSet('12345')

/sap/opu/odata/sap/ZSALESORDER_SRV/SalesOrderSet?$filter=Customer eq '1000'&$select=SalesOrder,NetValue

Other query options you will use: $orderby , $skip , $expand (include related entities in one call) and, for a total count, $inlinecount=allpages in V2 or $count=true in V4.

Build a service with SEGW

The Gateway Service Builder ( SEGW ) is the classic way to create OData V2 services and is still common on ECC and S/4HANA projects.

• Create a project and define entity types and entity sets, by hand or with right-click Data Model > Import > DDIC Structure .

• Click Generate Runtime Objects . SEGW creates the model provider classes ( ..._MPC , ..._MPC_EXT ) and data provider classes ( ..._DPC , ..._DPC_EXT ).

• In ..._DPC_EXT , redefine methods such as SALESORDERSET_GET_ENTITYSET (list), ..._GET_ENTITY (one record), ..._CREATE_ENTITY , ..._UPDATE_ENTITY and ..._DELETE_ENTITY . Change only the _EXT classes; the others are rebuilt on every generation.

• Register the service in /IWFND/MAINT_SERVICE ( Add Service ) and test it in /IWFND/GW_CLIENT .

• When a call fails, read /IWFND/ERROR_LOG and /IWBEP/ERROR_LOG .

METHOD salesorderset_get_entityset.

SELECT vbeln AS salesorder, kunnr AS customer, netwr AS netvalue

FROM vbak

INTO CORRESPONDING FIELDS OF TABLE @et_entityset

UP TO 100 ROWS.

ENDMETHOD.

The current way: RAP service binding

For new development on S/4HANA and in ABAP Cloud, services are built with the ABAP RESTful Application Programming Model (RAP) in ADT instead of SEGW:

• Model the data as CDS view entities, plus a behavior definition if the service must write.

• Create a service definition that lists what to expose (example below).

• Create a service binding on it, choose OData V4 - UI , OData V2 - UI or a Web API type, and click Publish . Preview opens a Fiori elements app straight away.

define service ZUI_SALESORDER {

expose ZC_SalesOrder as SalesOrder;

}

Key takeaways

• OData is REST over HTTP: entity sets, a service document and $metadata .

• Gateway V2 URLs follow /sap/opu/odata/sap/<SERVICE>/ ; test them in /IWFND/GW_CLIENT .

• In SEGW, code only in the _DPC_EXT and _MPC_EXT classes, then register in /IWFND/MAINT_SERVICE .

• For new work, use CDS plus a service definition and service binding (RAP).

• Errors first: /IWFND/ERROR_LOG and /IWBEP/ERROR_LOG .

Want to build and test OData services on a real system with a trainer? See our SAP ABAP Development course .