ERPClimb logoERPClimb
OData Gateway
Architect / Cross-trackintermediate 8 min read

OData Gateway Part 3: $expand, Navigation, Deep Insert and $batch

Preview · a free account unlocks the full lesson

Key takeaway

Handle related data in SEGW services: associations and navigation properties, navigation reads in GET ENTITYSET, $expand via GET EXPANDED ENTITY, deep insert of header with items via CREATE DEEP ENTITY, and $batch with changesets and commit rules.

In this lessonShow sections

Visual overview

OData Gateway Part 3: $expand, Navigation, Deep Insert and $batch — learning sheetFlow: Add entity SalesOrderItem, association and navigation ToItems; regenerate → Implement SALESORDERITEMSET_GET_ENTITYSET reading items for the source key → Test /SalesOrderSet('…')/ToItems and ?$expand=ToItems → Define the deep type in MPC_EXT and implement CREATE_DEEP_ENTITY. Key ideas: ASSOCIATION AND NAVIGATION; $EXPAND; DEEP INSERT; $BATCH. Watch out: $batch groups requests; modifying requests sit in changesets that succeed or fail together. Inside a changeset the framework controls the commit — no COMMIT WORK in your code there.ERPClimb.com / ARCH / LESSON 3/10 / LEARNING SHEETOData Gateway Part 3: $expand, Navigation, Deep Insert and$batch1 · HOW IT FLOWS1Add entitySalesOrderItem,association and…2ImplementSALESORDERITEMSET_GET_ENTITYSETreading items…3Test/SalesOrderSet('…')/ToItemsand…4Define the deeptype in MPC_EXTand implement…2 · KEY IDEAS EXPLAINEDAssociation And NavigationSEGW → Data Model → Associations: SalesOrder (1)to SalesOrderItem (N), referential constraintSalesOrder = SalesOrder.Navigation property ToItems on SalesOrder.$Expand/SalesOrderSet('4711')?$expand=ToItems returnsheader with nested items.Default: framework calls child GET_ENTITYSET perparent — fine for one parent, slow for lists.Deep InsertClient POSTs header JSON with nested"ToItems": [ … ].Define a deep type in MPC_EXT (header fields +items table named like the navigation property).$BatchOne HTTP POST to /$batch containing severalrequests.GET requests outside changesets; modifyingrequests inside changesets (all-or-nothing).3 · REMEMBER · WATCH OUTRememberAssociations and navigation properties link entity types (SalesOrder →ToItems); the client follows them with /SalesOrderSet('4711')/ToItems…Without custom code, $expand calls GET_ENTITYSET of the child once perparent (N+1 calls); redefining GET_EXPANDED_ENTITY /…Deep insert (POST header with nested items) is handled inCREATE_DEEP_ENTITY with a deep structure defined in MPC_EXT.!Watch out$batch groups requests; modifyingrequests sit in changesets thatsucceed or fail together. Inside achangeset the framework controls thecommit — no COMMIT WORK in your codethere.4 · IN A REAL PROJECTA Fiori order list used $expand=ToItems on 200 orders. The service had no expanded-read implementation, so theframework called the item GET_ENTITYSET 200 times; the list took 14 seconds. The developer redefinedGET_EXPANDED_ENTITYSET: one SELECT for headers, one SELECT for all their items, then built the deep result and…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

Part 1 returned a flat list, but real apps need header and item data together, which is where associations and navigation come in. An association such as SalesOrder (1) to SalesOrderItem (N), with a referential constraint of SalesOrder = SalesOrder, is set up under SEGW's Data Model → Associations, and it produces a navigation property — ToItems on SalesOrder — that the client can follow with a request like /SalesOrderSet('4711')/ToItems, which calls SALESORDERITEMSET_GET_ENTITYSET with the parent key arriving in it_key_tab or io_tech_request_context as the source keys.

$expand works similarly: /SalesOrderSet('4711')?$expand=ToItems returns the header together with its nested items. By default, the framework simply calls the child's GET_ENTITYSET once per parent, which is fine for a single parent but slow for a list — the classic N+1 problem. The fix is to redefine SALESORDERSET's own GET_EXPANDED_ENTITY (for a single read) or GET_EXPANDED_ENTITYSET (for a list), filling a deep structure directly and reporting the navigation as already handled in et_expanded_tech_clauses.

Free account

Create a free account to keep reading

You have read the opening of this lesson. A free ERPClimb account unlocks the rest of it, every other lesson and topic, and your learning history, so you can pick up exactly where you stopped. No card needed.

  • Full explanation
  • Code example
  • Real project scenario
  • Common mistakes
  • Best practices
  • Interview angle

One tap with Google works too. Every topic keeps its first lesson open to everyone.

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.