OData Gateway Part 1: OData Basics and Your First SEGW Service
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.
What this complete series covers
Learn OData Gateway in a clear, practical sequence — from the basic idea to real project use, troubleshooting, and interview-ready understanding.
- Who it is for
- Best for SAP consultants, developers, and learners who want a practical understanding of OData Gateway.
- Prerequisites
- Some SAP project experience is helpful because the series connects architecture decisions across applications, integration, clean core, data, and operations.
- Final outcome
- By the end, you should be able to explain OData Gateway clearly, follow the main end-to-end flow, apply it in a project scenario, and troubleshoot the most common issues.
- Part 1: OData Gateway Part 1: OData Basics and Your First SEGW Service
Understand SEGW OData V2 modeling: entity types define properties and keys, entity sets expose collections, and generated MPC/DPC runtime classes implement metadata and data operations.
- Part 2: OData Gateway Part 2: SEGW vs RAP — Two Ways to Build OData
Choose SEGW or RAP from platform, lifecycle and business-object needs: maintain classic Gateway V2 services where appropriate, but use RAP and released APIs for modern S/4HANA deve
- Part 3: OData Gateway Part 3: $expand, Navigation, Deep Insert and $batch
Use OData V2 $batch, $expand and deep insert for different performance and transactional needs, and troubleshoot them with SAP Gateway metadata, client and error logs.
- Part 4: OData Gateway Part 4: Gateway Architecture — Hub vs Embedded
Understand SAP Gateway deployment so you know where OData registration, protocol processing and business implementation execute in hub versus embedded architectures and where to debug each failure.
- Part 5: OData Gateway Part 5: Service Registration, $metadata and Gateway Client Testing
Activate and test classic SAP Gateway OData V2 services by validating runtime artifacts, service registration, system alias, $metadata and entity calls before debugging frontend applications.
- Part 6: OData Gateway Part 6: GET_ENTITY and Key Handling
Implement OData V2 GETENTITY safely by reading and converting key predicates correctly, applying authorization and returning a controlled business or not-found error instead of an initial structure.
- Part 7: OData Gateway Part 7: GET_ENTITYSET with Filters, Paging and Sorting
Implement OData V2 GETENTITYSET as a bounded query: translate supported $filter conditions to database predicates, honor paging and sorting deliberately and never return an unrestr
- Part 8: OData Gateway Part 8: CREATE_ENTITY, UPDATE_ENTITY and DELETE_ENTITY
Implement OData V2 create, update and delete operations by reading typed payloads, validating business rules, delegating to supported backend APIs, returning structured messages an
- Part 9: OData Gateway Part 9: Error Handling and the Message Container
Return OData V2 errors through SAP Gateway business or technical exceptions and message containers so clients receive structured actionable feedback instead of dumps or generic HTTP failures.
- Part 10: OData Gateway Part 10: Debugging OData Services
Debug SAP Gateway OData requests by reproducing the exact call, identifying the real backend user, inspecting Gateway and backend error logs, then tracing request keys, filters, pa
System and release assumptions: Architecture guidance is release-aware and clean-core oriented. Exact product capabilities and supported extension points should be checked against the target SAP release.
Explanation
📌 KEY POINTS
✅ OData is a REST-based protocol: resources (entity sets) addressed by URLs, read and changed with HTTP GET, POST, PUT/PATCH/MERGE, DELETE, returned as JSON or XML.
✅ 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 Runtime Objects" creates MPC (model) and DPC (data) classes — your code goes only into the _EXT classes.
⚠️ Never change the generated base classes (MPC, DPC) — they are overwritten on every regeneration. Redefine methods in DPC_EXT.
━━━━━━━━━━━━━━━━━━━━
▶ WHAT THIS SERIES COVERS
- Part 1: OData basics and your first SEGW service
- Part 2: SEGW vs RAP — two ways to build OData
- Part 3: $expand, navigation, deep insert and $batch
- Part 4: Gateway architecture: hub vs embedded
- Part 5: Service registration, $metadata and Gateway client testing
- Part 6: GET_ENTITY and key handling
- Part 7: GET_ENTITYSET with filters, paging and sorting
- Part 8: CREATE_ENTITY, UPDATE_ENTITY and DELETE_ENTITY
- Part 9: Error handling and the message container
- Part 10: Debugging OData services
━━━━━━━━━━━━━━━━━━━━
▶ 1. ODATA IN ONE PICTURE
- Service root: /sap/opu/odata/sap/ZSALES_SRV/
- Entity set: /SalesOrderSet — a collection.
- Single entity: /SalesOrderSet('0000004711') — by key.
- Navigation: /SalesOrderSet('0000004711')/ToItems
- Metadata: /$metadata — the service description (types, keys, associations).
- Query options: $filter, $top, $skip, $orderby, $select, $expand, $count/$inlinecount, $format=json.
━━━━━━━━━━━━━━━━━━━━
▶ 2. BUILDING BLOCKS
- Entity type: structure of one record (SalesOrder with properties SalesOrder, Customer, NetAmount).
- Property: one field with EDM type (Edm.String, Edm.Decimal, Edm.DateTime).
- Key: one or more properties identifying an entity.
- Entity set: the collection of entities of one type.
- Association + navigation property: relation between entity types (order → items).
━━━━━━━━━━━━━━━━━━━━
▶ 3. SEGW PROJECT
- Transaction SEGW → Create Project (package, description).
- Data Model → Import → DDIC Structure (e.g. a Z structure) to create an entity type quickly; mark key fields; tick "Create Default Entity Set".
- Generate Runtime Objects: creates ZCL_<PRJ>_MPC, ZCL_<PRJ>_MPC_EXT, ZCL_<PRJ>_DPC, ZCL_<PRJ>_DPC_EXT and the service registration in the backend.
━━━━━━━━━━━━━━━━━━━━
▶ 4. DATA PROVIDER METHODS
- For each entity set: <SET>_GET_ENTITYSET, <SET>_GET_ENTITY, <SET>_CREATE_ENTITY, <SET>_UPDATE_ENTITY, <SET>_DELETE_ENTITY.
- Redefine in DPC_EXT; unredefined methods return "not implemented".
- Exporting table et_entityset has the type from MPC (…_mpc=>tt_<type>).
━━━━━━━━━━━━━━━━━━━━
▶ 5. CLASSIC ABAP INSIDE THE METHOD
- The method is OO by nature, but the code inside can be classic: explicit DATA, SELECT INTO TABLE, LOOP AT … INTO work area, APPEND.
━━━━━━━━━━━━━━━━━━━━
▶ STEP BY STEP
- 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.
- Register and test (Part 5): /sap/opu/odata/sap/ZSALES_SRV/SalesOrderSet?$format=json
✅ CHECKPOINT: you can explain entity type vs entity set and return a list from GET_ENTITYSET.
Code example
* ===== 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.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.
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.
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.
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
1. In an OData service, what is the difference between an entity type and an entity set?
2. Which URL returns the description of an OData service (entity types, keys, properties, navigation)?
3. A developer adds logic to ZCL_ZSALES_DPC (not _EXT). What happens at the next "Generate Runtime Objects" in SEGW?
Interview questions
1. What is the difference between entity type and entity set in OData?
Answer it in your own words first, then compare.
2. What is OData?
Answer it in your own words first, then compare.
Reference-verified: the steps are checked against official SAP documentation and tutorials, and object and field names in the sample code are checked for consistency. The code has not been compiled or run on an SAP system by ERPClimb. Syntax marked release-dependent varies by SAP release, so check it in your own system.
More lessons in this topic
- OData Gateway Part 10: Debugging OData Services
- OData Gateway Part 2: SEGW vs RAP — Two Ways to Build OData
- OData Gateway Part 3: $expand, Navigation, Deep Insert and $batch
- OData Gateway Part 4: Gateway Architecture — Hub vs Embedded
- OData Gateway Part 5: Service Registration, $metadata and Gateway Client Testing
- OData Gateway Part 6: GET_ENTITY and Key Handling
- OData Gateway Part 7: GET_ENTITYSET with Filters, Paging and Sorting
- OData Gateway Part 8: CREATE_ENTITY, UPDATE_ENTITY and DELETE_ENTITY