ERPClimb logoERPClimb
OData V4
RAP / CDS / ODataintermediate 9 min read

OData V4 Part 4: Actions, Functions and Batch Processing

Preview · a free account unlocks the full lesson

Key takeaway

Call RAP business operations over OData V4: bound and unbound actions, actions with parameters, functions, draft actions, and $batch with change sets for atomic multi-step requests.

In this lessonShow sections

Visual overview

OData V4 Part 4: Actions, Functions and Batch Processing — learning sheetFlow: Look up the action and function names in $metadata → Call approve on a submitted request (active instance) → Call reject with a reason → Build a JSON batch with one change set: create request + create item (code example). Key ideas: ACTIONS (CHANGE DATA); ACTIONS WITH PARAMETERS; FUNCTIONS (READ ONLY); DRAFT ACTIONS OVER ODATA. Watch out: WATCH OUT: an error in one change set rolls back that change set only; other change sets in the same batch can still succeed.ERPClimb.com / RAP / LESSON 4/6 / LEARNING SHEETOData V4 Part 4: Actions, Functions and Batch Processing1 · HOW IT FLOWS1Look up theaction andfunction names…2Call approve ona submittedrequest (active…3Call reject witha reason4Build a JSONbatch with onechange set…2 · KEY IDEAS EXPLAINEDActions (Change Data)Declared in the BDEF and used in the projectionBDEF ("use action approve;").Bound action (instance action): POST on theentity, followed by the qualified action name. InRAP V4 services the name is namespaced, e.g…Actions With ParametersParameters from the abstract entity (e.g.ZD_RejectReason) are sent as JSON body: {"Reason": "Budget exceeded" }.Functions (Read Only)Declared as "function" in the BDEF;called with GET and parameters in parentheses: GET…/PurchaseRequest(…)/<namespace>.getApprovalLevel().Draft Actions Over ODataEdit: POST on the active instance…(IsActiveEntity=true)/<ns>.Edit with {"PreserveChanges": true } → returns the…Prepare and Activate: POST on the draft instance…(IsActiveEntity=false)/<ns>.Prepare /<ns>.Activate.3 · REMEMBER · WATCH OUTRememberActions change data → POST; functions only read → GET.Bound actions are called on an entity:…/PurchaseRequest(…)/<namespace>.approve.$batch bundles requests; a change set is processed atomically (all ornothing).!Watch outWATCH OUT: an error in one changeset rolls back that change set only;other change sets in the same batchcan still succeed.4 · IN A REAL PROJECTA partner system created purchase requests and then called approve in two separate HTTP calls. When approvefailed (e.g. missing budget), the request remained unapproved, and the partner created a new one on retry —producing duplicates. The team changed the integration: the partner sends a JSON $batch with one change set…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

Actions change data, so they're called with POST; functions only read data, so they're called with GET. A bound action is called on a specific entity, as in …/PurchaseRequest(…)/<namespace>.approve. $batch bundles several requests together, and a change set within it is processed atomically — all or nothing. The exact action name, including its namespace, always comes from $metadata, so that's the place to copy it from rather than guessing.

Parts 1 through 3 covered reading and CRUD. Business APIs also need commands like approve, reject or copy, along with multi-step requests, and this part shows how RAP operations show up in OData V4.

Actions that change data are declared in the BDEF and selected in the projection BDEF with something like "use action approve;".

A bound, or instance, action is called with POST on the entity followed by the qualified action name — in RAP V4 services this name is namespaced, something like com.sap.gateway.srvd.zui_purchreq.v0001.approve, and the exact form should always be checked in $metadata. The result, when the action declares "result [1] $self", is the returned entity in the response body.

A static action, by contrast, is bound to the entity collection rather than an instance, as in POST …/PurchaseRequest/<namespace>.createFromTemplate, and a factory action of this kind returns the newly created instance.

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.