ERPClimb logoERPClimb
OData Gateway
Architect / Cross-trackbeginner 7 min read

OData Gateway Part 1: OData Basics and Your First SEGW Service

Free sample lesson · open to everyone

Key takeaway

Learn what OData is and why SAP uses it for Fiori and integrations, the building blocks (entity type, entity set, property, key, association, navigation), how a SEGW project generates MPC and DPC classes, and how to return data from GET ENTITYSET with classic ABAP.

In this lessonShow sections

Visual overview

OData Gateway Part 1: OData Basics and Your First SEGW Service — learning sheetFlow: Create a DDIC structure ZS_SO_HEAD (VBELN, ERDAT, KUNNR, NETWR, WAERK) → SEGW: create project ZSALES, import the structure as entity type SalesOrder with key SalesOrder, entity set SalesOrderSet → Generate runtime objects → Redefine SALESORDERSET_GET_ENTITYSET in ZCL_ZSALES_DPC_EXT with the code example. Key ideas: ODATA IN ONE PICTURE; BUILDING BLOCKS; SEGW PROJECT; DATA PROVIDER METHODS. Watch out: Never change the generated base classes (MPC, DPC) — they are overwritten on every regeneration. Redefine methods in DPC_EXT.ERPClimb.com / ARCH / LESSON 1/10 / LEARNING SHEETOData Gateway Part 1: OData Basics and Your First SEGWService1 · HOW IT FLOWS1Create a DDICstructureZS_SO_HEAD…2SEGWcreate project ZSALES,import the structure as…3Generate runtimeobjects4RedefineSALESORDERSET_GET_ENTITYSETin…2 · KEY IDEAS EXPLAINEDOData In One PictureService root: /sap/opu/odata/sap/ZSALES_SRV/Entity set: /SalesOrderSet — a collection.Building BlocksEntity type: structure of one record (SalesOrderwith properties SalesOrder, Customer, NetAmount).Property: one field with EDM type (Edm.String,Edm.Decimal, Edm.DateTime).SEGW ProjectTransaction SEGW → Create Project (package,description).Data Model → Import → DDIC Structure (e.g. a Zstructure) to create an entity type quickly; markkey fields; tick "Create Default Entity…Data Provider MethodsFor each entity set: <SET>_GET_ENTITYSET,<SET>_GET_ENTITY, <SET>_CREATE_ENTITY,<SET>_UPDATE_ENTITY…Redefine in DPC_EXT; unredefined methods return"not implemented".3 · REMEMBER · WATCH OUTRememberOData is a REST-based protocol: resources (entity sets) addressed byURLs, read and changed with HTTP GET, POST, PUT/PATCH/MERGE, DELETE…SAP Gateway makes ABAP data available as OData; Fiori apps, SAP BTP,mobile apps and third-party systems consume it.In SEGW you model entity types and entity sets; "Generate RuntimeObjects" creates MPC (model) and DPC (data) classes — your code…!Watch outNever change the generated baseclasses (MPC, DPC) — they areoverwritten on every regeneration.Redefine methods in DPC_EXT.4 · IN A REAL PROJECTA warehouse team wanted a simple mobile app showing open deliveries. The first idea was an RFC function calledfrom a custom middleware, with its own authentication and mapping. The ABAP team instead built a small SEGWservice with one entity set DeliverySet, redefined GET_ENTITYSET in DPC_EXT and registered it. The mobile app…Original ERPClimb learning sheet • Verify against your SAP release and edition

Expert visual walkthrough

RAP · CDS · ODATA ACADEMY · Integration pathERPClimb.com

OData Basics and Your First SEGW Service

OData Gateway · Chapter-specific technical teaching map

Integration path

1Concept

API client

2Concept

OData contract

3Concept

Gateway / RAP runtime

4Concept

HTTP response

Tutor's chapter takeaway

Learn what OData is and why SAP uses it for Fiori and integrations, the building blocks (entity type, entity set, property, key, association, navigation), how a SEGW project generates MPC and DPC classes, and how to return data from GET_ENTITYSET with classic ABAP.

In a real project

A warehouse team wanted a simple mobile app showing open deliveries. The first idea was an RFC function called from a custom middleware, with its own authentication and mapping. The ABAP team instead built a small SEGW…

Watch out for

• Coding in the generated MPC/DPC base classes — lost on regeneration. • Forgetting to mark key properties, causing duplicate or broken entities. • Returning thousands of rows without paging. • Confusing entity type…

Conceptual study map, not an SAP configuration screenshot or a guaranteed runtime sequence. Consult the lesson for implementation prerequisites and exceptions.

The situation: a real project scenario

A warehouse team wanted a simple mobile app showing open deliveries. The first idea was an RFC function called from a custom middleware, with its own authentication and mapping.
The ABAP team instead built a small SEGW service with one entity set DeliverySet, redefined GET_ENTITYSET in DPC_EXT and registered it. The mobile app consumed standard OData JSON over HTTPS with SAP logon, and the same service was later reused by a Fiori app without changes.

Explanation

OData is a REST-based protocol: resources, exposed as entity sets, are addressed by URLs and read or changed with HTTP GET, POST, PUT/PATCH/MERGE, and DELETE, returning JSON or XML. SAP Gateway is what makes ABAP data available as OData, and it's consumed by Fiori apps, SAP BTP, mobile apps, and third-party systems alike.

This series covers the whole topic in ten parts: OData basics and your first SEGW service (this part), SEGW versus RAP as two ways to build OData, $expand/navigation/deep insert/$batch, Gateway architecture (hub versus embedded), service registration and $metadata and Gateway client testing, GET_ENTITY and key handling, GET_ENTITYSET with filters/paging/sorting, CREATE_ENTITY/UPDATE_ENTITY/DELETE_ENTITY, error handling and the message container, and finally debugging OData services.

In one picture: a service root looks like /sap/opu/odata/sap/ZSALES_SRV/, an entity set is a collection such as /SalesOrderSet, a single entity is addressed by key as /SalesOrderSet('0000004711'), and navigation looks like /SalesOrderSet('0000004711')/ToItems. The service's own description — its types, keys, and associations — lives at /$metadata, and query options such as $filter, $top, $skip, $orderby, $select, $expand, $count/$inlinecount, and $format=json shape what comes back.

The building blocks behind this are: an entity type, which is the structure of one record (a SalesOrder with properties SalesOrder, Customer, NetAmount); a property, one field with an EDM type such as Edm.String, Edm.Decimal, or Edm.DateTime; a key, one or more properties identifying an entity; an entity set, the collection of entities of one type; and an association with a navigation property, the relation between entity types, such as an order pointing to its items.

Building this in SEGW starts with transaction SEGW and Create Project (giving a package and description).

Under Data Model → Import → DDIC Structure, you can import a Z structure to quickly create an entity type, mark its key fields, and tick "Create Default Entity Set." Generate Runtime Objects then creates ZCL_<PRJ>_MPC, ZCL_<PRJ>_MPC_EXT, ZCL_<PRJ>_DPC, and ZCL_<PRJ>_DPC_EXT, along with the service registration in the backend.

It's important never to change the generated base classes (MPC, DPC) directly, since they're overwritten on every regeneration — your own code goes only into the _EXT classes, where you redefine methods.

For each entity set, there's a standard set of data provider methods: <SET>_GET_ENTITYSET, <SET>_GET_ENTITY, <SET>_CREATE_ENTITY, <SET>_UPDATE_ENTITY, and <SET>_DELETE_ENTITY. These get redefined in DPC_EXT; any method left un-redefined simply returns "not implemented." The exporting table et_entityset takes its type from MPC (…_mpc=>tt_<type>). Even though the method itself is object-oriented by nature, the code inside it can be entirely classic ABAP: explicit DATA declarations, SELECT INTO TABLE, LOOP AT ... INTO a work area, and APPEND all work as usual.

To put this into practice: create a DDIC structure ZS_SO_HEAD (VBELN, ERDAT, KUNNR, NETWR, WAERK), create a SEGW project called ZSALES and import that structure as entity type SalesOrder with key SalesOrder and entity set SalesOrderSet, generate the runtime objects, redefine SALESORDERSET_GET_ENTITYSET in ZCL_ZSALES_DPC_EXT, and then register and test it (covered in Part 5) at /sap/opu/odata/sap/ZSALES_SRV/SalesOrderSet?$format=json. By the end you should be able to explain entity type versus entity set and return a list from GET_ENTITYSET.

Code example

ABAP Code
* ===== STEP 1: DPC_EXT - redefine SALESORDERSET_GET_ENTITYSET =====* Class ZCL_ZSALES_DPC_EXT (generated by SEGW, project ZSALES)METHOD salesorderset_get_entityset.   DATA: lt_vbak TYPE STANDARD TABLE OF vbak,        ls_vbak TYPE vbak,        ls_so   TYPE zcl_zsales_mpc=>ts_salesorder. * ===== STEP 2: read data - classic SELECT, limited rows =====  SELECT vbeln erdat kunnr netwr waerk    FROM vbak    INTO CORRESPONDING FIELDS OF TABLE lt_vbak    UP TO 100 ROWS    WHERE auart = 'TA'. * ===== STEP 3: map DB fields to entity properties =====  LOOP AT lt_vbak INTO ls_vbak.    CLEAR ls_so.    ls_so-salesorder = ls_vbak-vbeln.    ls_so-createdon  = ls_vbak-erdat.    ls_so-customer   = ls_vbak-kunnr.    ls_so-netamount  = ls_vbak-netwr.    ls_so-currency   = ls_vbak-waerk.    APPEND ls_so TO et_entityset.  ENDLOOP. ENDMETHOD. * ===== STEP 4: test URLs (Gateway client /IWFND/GW_CLIENT) =====* /sap/opu/odata/sap/ZSALES_SRV/$metadata* /sap/opu/odata/sap/ZSALES_SRV/SalesOrderSet?$format=json* Paging, filters and sorting are added in Part 7.

Watch out

Common mistakes

  • Coding in the generated MPC/DPC base classes — lost on regeneration.
  • Forgetting to mark key properties, causing duplicate or broken entities.
  • Returning thousands of rows without paging.
  • Confusing entity type (structure) with entity set (collection).
  • Mapping fields manually but forgetting properties, so the UI shows empty columns.

Do this

Best practices

  • Code only in DPC_EXT and MPC_EXT.
  • Keep entity property names business-oriented (SalesOrder, not VBELN).
  • Import from a DDIC structure to keep types consistent.
  • Always support paging from the start (Part 7).
  • Test with $metadata before coding the consumer.

In the interview

Interview angle

Questions: "What is OData?", "Difference between entity type and entity set?", "What are MPC and DPC classes?"
Strong answer: OData is a REST protocol exposing entity sets over HTTP with CRUD verbs, $metadata and query options. Entity type = structure, entity set = collection. SEGW generates MPC (model definition) and DPC (data provider) with _EXT subclasses; custom code is placed in DPC_EXT by redefining GET_ENTITYSET etc., never in the generated base classes.

Practice this lesson

Quick check

0 of 3 questions attempted

Question 1 of 3

In an OData service, what is the difference between an entity type and an entity set?

Practise this in an interview

Answer in your own words and get instant feedback, the way an interviewer would judge it.

1What is the difference between entity type and entity set in OData?

2What is OData?

Try a related Code Lab

This published exercise covers the same SAP topic. Apply the ideas in a hands-on scenario, then return to review your answers.

Open: OData Error Returned as Generic 500 →

Was this lesson helpful?

Keep exploring

Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.