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

OData V4 Part 6: ETags and Optimistic Concurrency

Preview · a free account unlocks the full lesson

Key takeaway

Understand optimistic concurrency in OData V4 with RAP: how ETags are delivered, how clients send If-Match, what 412 and 428 mean, and how RAP etag master fields drive the whole mechanism.

In this lessonShow sections

Visual overview

OData V4 Part 6: ETags and Optimistic Concurrency — learning sheetFlow: GET a request and note @odata.etag → PATCH it with If-Match → 200, new ETag → PATCH again with the OLD ETag → 412 → PATCH without If-Match → 428 (if required). Key ideas: THE PROBLEM; HOW ETAGS SOLVE IT; 428 PRECONDITION REQUIRED; IF-MATCH: *. Watch out: If-Match: * disables the check — never use it in business clients.ERPClimb.com / RAP / LESSON 6/6 / LEARNING SHEETOData V4 Part 6: ETags and Optimistic Concurrency1 · HOW IT FLOWS1GET a requestand note@odata.etag2PATCH it withIf-Match → 200,new ETag3PATCH again withthe OLD ETag →4124PATCH withoutIf-Match → 428(if required)2 · KEY IDEAS EXPLAINEDThe ProblemTwo users read the same request at 9:00. User Achanges the amount at 9:05. User B changes thedescription at 9:10 based on the 9:00 data…How ETAGs Solve ItIn RAP, "etag master LocalLastChangedAt"defines the version field. Its value changes onevery change.When a client reads an entity, OData returns theversion as "@odata.etag" in the JSON(and as ETag header for single entities), e.g…428 Precondition RequiredIf an ETag is defined and the client sends noIf-Match, the service can reject the request with428. This forces clients to take part in…If-Match: *"*" means "any version". Itbypasses the check and brings back lost updates.Use it only for tools that intentionally overwrite…3 · REMEMBER · WATCH OUTRememberThe server sends the ETag with every read (@odata.etag / ETag header).The client sends it back in If-Match on PATCH, DELETE and actions.Mismatch → 412 Precondition Failed; missing If-Match where required →428.!Watch outIf-Match: * disables the check —never use it in business clients.4 · IN A REAL PROJECTA custom mobile app for approvers used If-Match: * because "412 errors were annoying". Two approversoccasionally worked on the same request; the second approval overwrote a budget correction made minutesearlier, and a request was approved with the old amount. The app was changed to store @odata.etag, send it…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

The server sends an ETag with every read, exposed as @odata.etag in the JSON or as an ETag header for single entities. The client is expected to send it back in If-Match on PATCH, DELETE and action calls. A mismatch produces 412 Precondition Failed, while a missing If-Match where one is required produces 428. If-Match: * disables the check entirely and should never be used in a business client.

Parts 1 through 5 covered calls and errors; this final part explains one mechanism that every write client must implement: ETags, with RAP Business Objects Part 4 covering the matching BO-side behavior.

The underlying problem is this: two users read the same request at 9:00. User A changes the amount at 9:05. User B changes the description at 9:10, still working from the 9:00 data. Without protection, B's write would silently win, and B would never even see that A had made a change. Locks can't help here, because the two changes weren't simultaneous — this is a lost-update problem, not a concurrency-timing problem.

ETags solve this by versioning each entity. In RAP, "etag master LocalLastChangedAt" defines which field acts as the version field, and its value changes on every update. When a client reads an entity, OData returns that version as "@odata.etag" in the JSON, and as an ETag header for single entities — for example, W/"20260924090000.1234560".

When the client later sends a PATCH, DELETE or action, it includes that value as If-Match: W/"20260924090000.1234560". RAP then compares it against the current value: if they're equal, the change is allowed; if they differ, the server returns 412 Precondition Failed, and the client must re-read the data and let the user decide how to proceed.

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.