ERPClimb logoERPClimb
OData V2
RAP / CDS / ODataintermediate 8 min read

OData V2 Part 2: Deep Insert, Batch and Navigation Design

Preview · a free account unlocks the full lesson

Key takeaway

Design OData V2 navigation and write operations: associations and navigation properties, $expand, deep insert of header and items, $batch with change sets, and the implementation side in SEGW (CREATE DEEP ENTITY, changeset methods).

In this lessonShow sections

Visual overview

OData V2 Part 2: Deep Insert, Batch and Navigation Design — learning sheetFlow: Check the Header–Item association and navigation in $metadata → Read with $expand=ToItems → Send a deep insert (code example) → For SEGW services: implement CREATE_DEEP_ENTITY and changeset handling as shown. Key ideas: NAVIGATION DESIGN; DEEP INSERT; $BATCH AND CHANGESETS; COMMITS IN SEGW. Watch out: In SEGW you implement all of this yourself — in RAP V2 bindings the framework does it.ERPClimb.com / RAP / LESSON 2/3 / LEARNING SHEETOData V2 Part 2: Deep Insert, Batch and Navigation Design1 · HOW IT FLOWS1Check theHeader–Itemassociation and…2Read with$expand=ToItems3Send a deepinsert (codeexample)4For SEGWservicesimplementCREATE_DEEP_ENTITY and…2 · KEY IDEAS EXPLAINEDNavigation DesignIn the model: Association (Header 1 : n Item) +NavigationProperty (ToItems on Header, ToHeader onItem).Clients: /PurchaseRequestSet('4711')/ToItems or?$expand=ToItems.Deep InsertClient sends one POST with nested items: {"RequestID": "","Description": "…"…Server (SEGW): redefine/IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_DEEP_ENTITYin the DPC_EXT class; read the nested data with…$Batch And ChangesetsV2 $batch is a multipart/mixed request: readrequests outside changesets, write requests insidechangesets.A changeset should be processed as one LUW: all ornothing.Commits In SEGWThe gateway framework commits at the end of asuccessful request/changeset. Don't call COMMITWORK inside CRUD methods; raise…3 · REMEMBER · WATCH OUTRememberNavigation properties (from associations) let clients read relateddata: /Header('1')/ToItems or $expand.Deep insert = POST a header with its items in one request; SEGWimplements CREATE_DEEP_ENTITY.$batch (multipart) with changesets groups writes into one logical unitof work.!Watch outIn SEGW you implement all of thisyourself — in RAP V2 bindings theframework does it.4 · IN A REAL PROJECTA SEGW service accepted header and items in separate calls from a UI5 app. When item creation failed, headerswithout items remained, and users created them again — leading to duplicates and manual cleanup. The teamimplemented CREATE_DEEP_ENTITY with a single business-logic call and proper exception handling, so header and…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

Part 1 covered reading V2 services. This part covers relationships and complex writes — the area where many V2 projects actually struggle.

Navigation design in V2 relies on two things in the model: an Association between Header and Item (1 : n), and a NavigationProperty — ToItems on Header, ToHeader on Item. Clients then read related data with something like /PurchaseRequestSet('4711')/ToItems, or with ?$expand=ToItems. A good design rule is to model only the navigation the UI actually needs, and to avoid huge $expand chains inside list views. In SEGW, $expand is handled generically by default, calling the item's GET_ENTITYSET once per header, unless GET_EXPANDED_ENTITYSET is implemented explicitly for better performance.

Deep insert lets a client send one POST carrying nested items, such as { "RequestID": "", "Description": "…", "ToItems": [ { … }, { … } ] }. On the server side in SEGW, this means redefining /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_DEEP_ENTITY in the DPC_EXT class, reading the nested data with io_data_provider->read_entry_data into a deep structure, creating the header and its items in one call to the business logic, and returning the created structure. In a RAP V2 binding, by contrast, deep insert works automatically through the composition, with no equivalent code needed.

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.