ERPClimb logoERPClimb
Managed RAP
RAP / CDS / ODataintermediate 14 min read

Managed RAP Part 2: Numbering, Locking, ETags and Authorization

Preview · a free account unlocks the full lesson

Key takeaway

Add the transactional controls to the Purchase Request object: a technical UUID plus a readable request number, pessimistic locks, optimistic ETag concurrency, and global and instance authorization.

In this lessonShow sections

Visual overview

Managed RAP Part 2: Numbering, Locking, ETags and Authorization — learning sheetFlow: Create number range object ZPR_REQ with interval 01 (e.g. 0000000001–9999999999) → Create authorization object ZPR_REQ with field ACTVT (activities 01 create, 02 change, 06 delete) and assign it to your test role → Add the determination "setRequestID on save { create; }" to the root behavior and let the quick fix create the method → Implement setRequestID, get_global_authorizations and get_instance_authorizations as in the code example. Key ideas: NUMBERING — TWO KEYS, TWO JOBS; LOCKING — PESSIMISTIC CONTROL; ETAG — OPTIMISTIC CONTROL; AUTHORIZATION — WHO MAY DO WHAT. Watch out: Semantic numbers from a number range belong in an on-save determination.ERPClimb.com / RAP / LESSON 2/5 / LEARNING SHEETManaged RAP Part 2: Numbering, Locking, ETags andAuthorization1 · HOW IT FLOWS1Create numberrange objectZPR_REQ with…2Createauthorizationobject ZPR_REQ…3Add thedetermination"setRequestID…4ImplementsetRequestID,get_global_authorizations…2 · KEY IDEAS EXPLAINEDNumbering — Two Keys, Two JobsA technical key (RequestUUID) — never shown tousers, never changes, generated by the framework.A semantic key (RequestID, e.g. 0000000042) — whatusers search for and quote in emails.Locking — Pessimistic Control"lock master" on the root and "lockdependent by _Request" on the item mean:whenever anyone changes a request or any of its…ETag — Optimistic ControlLocks protect a single transaction. ETags protectthe gap between reading and changing. Typicalcase: user A opens a request at 10:00, user B…Authorization — Who May Do Whatget_global_authorizations — checks operations thatdo not depend on a specific instance, mostimportantly create. Example: is this user allowed…get_instance_authorizations — checks operations onan existing instance: update, delete, actions.Example: may this user change request 42?3 · REMEMBER · WATCH OUTRememberLocks stop simultaneous edits; ETags stop saving from an outdatedscreen.Root = lock master + etag master; children = lock/authorizationdependent.Global authorization checks create; instance authorization checksupdate/delete/actions.!Watch outSemantic numbers from a number rangebelong in an on-save determination.4 · IN A REAL PROJECTTwo buyers in the same purchasing team edited the same request from different Fiori sessions. The originaldesign had no ETag, so the buyer who saved last silently overwrote the first buyer's quantity change, andnobody noticed until the supplier shipped the wrong amount. Adding "etag master LocalLastChangedAt"…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

In Part 1 you built ZR_PurchReq with CRUD already working and no code written. It already carries three declarations that haven't been used yet: numbering, lock master, etag master and authorization master. This part works through each one and implements whatever actually needs code.

A good RAP business object usually carries two identifiers serving two different jobs: a technical key, RequestUUID, which is never shown to users, never changes, and is generated by the framework; and a semantic key, RequestID, something like 0000000042, which is what users actually search for and quote in emails. There are several numbering options for the technical key.

Managed early numbering, declared with "numbering : managed" on a UUID field, has the framework generate the UUID the moment the instance is created — the simplest option, and the one used here. Unmanaged early numbering, declared with "early numbering" in the entity header, requires implementing an earlynumbering_create method and assigning keys by hand during the interaction phase.

Late numbering, declared with "late numbering", uses a temporary key until save and assigns the final key in the saver method adjust_numbers — useful only when the final number must be gap-free and should only be drawn once the save is certain. External numbering simply has the consumer supply the key, with the field marked readonly : update.

For the semantic RequestID, this lesson uses a determination on save that draws a number from a number range object, ZPR_REQ (created in ADT as a Number Range Object, interval 01) — drawing the number at save time means a request that's never actually saved never consumes a number.

Locking provides pessimistic control. "lock master" on the root and "lock dependent by _Request" on the item mean that whenever anyone changes a request or any of its items, the framework locks the whole request, so a second user trying to edit the same request gets a lock error instead of silently overwriting it.

In managed RAP, no lock code needs to be written — the framework locks by the root key (in unmanaged RAP, the lock method has to be implemented by hand, as covered in the Unmanaged series).

Locks are exclusive and last until the transaction ends; with draft, covered in Part 4, the lock is held for the entire editing session of the draft.

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.