ERPClimb logoERPClimb
RAP Basics
Architect / Cross-trackadvanced 9 min read

RAP Basics Part 11: Draft, Locking and Authorization

Preview · a free account unlocks the full lesson

Key takeaway

Make a RAP BO safe for real multi-user use: draft handling (draft tables, Edit/Activate/Discard/Resume/Prepare, total ETag), pessimistic locking (lock master) and optimistic concurrency (ETags), and authorization at two levels — read access via CDS DCL and modify access via authorization master (global/instance).

In this lessonShow sections

Visual overview

RAP Basics Part 11: Draft, Locking and Authorization — learning sheetFlow: Add with draft; and create draft tables via quick fix → Add total etag and draft actions, include Prepare validations → Add authorization master ( global, instance ) and implement both methods → Create a DCL role for read access. Key ideas: DRAFT; LOCKING; ETAGS (OPTIMISTIC); AUTHORIZATION — READ. Watch out: A BO with DCL but no authorization master lets every user who can open the app change every record they can see.ERPClimb.com / ARCH / LESSON 11/11 / LEARNING SHEETRAP Basics Part 11: Draft, Locking and Authorization1 · HOW IT FLOWS1Add with draft;and create drafttables via quick…2Add total etagand draftactions, include…3Addauthorizationmaster ( global…4Create a DCLrole for readaccess2 · KEY IDEAS EXPLAINEDDraftBDEF header: with draft; entity: draft tableztravel_d (generated via quick fix).Draft actions: Edit, Activate optimized, Discard,Resume, Prepare.LockingPessimistic: lock master on root, lock dependentby _Travel on children.Managed BO: framework sets the enqueue lock;unmanaged: implement lock method.ETAGs (Optimistic)etag master LocalLastChangedAt — instance ETag inOData (If-Match header).total etag LastChangedAt — for draft; checked onResume/Activate.Authorization — Read@AccessControl.authorizationCheck: #CHECK + DCLrole with pfcg_auth mapping.Restricts which rows a user can see (Part 8 of CDSViews).3 · REMEMBER · WATCH OUTRememberDraft lets users save incomplete work on the server: changes live in adraft table until Activate copies them to the active table.Locking: lock master takes an exclusive lock on the active instance(for draft: when editing starts); ETags detect that the data changed…Draft needs a total ETag (lock master total etag LastChangedAt) todetect changes to the active instance while a draft exists.!Watch outA BO with DCL but no authorizationmaster lets every user who can openthe app change every record they cansee.4 · IN A REAL PROJECTAfter go-live of a draft-enabled promotion BO, planners complained that their changes "disappeared".Analysis showed two planners editing the same promotion: the BO had an instance ETag but no total ETag, andthe draft of planner A was activated over changes planner B had activated minutes earlier. Adding lock master…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

This final part is about making the business object ready for many users working at the same time. Draft lets users save incomplete work on the server: changes live in a draft table until Activate copies them into the active table.

In the BDEF header this is declared with with draft; entity: draft table ztravel_d, generated via quick fix, and the available draft actions are Edit, Activate optimized, Discard, Resume, and Prepare. Children need their own declaration too, for example association _Booking { create; with draft; }, and %is_draft inside %tky is what distinguishes a draft instance from an active one.

Locking in RAP is pessimistic by default: a lock master takes an exclusive lock on the active instance (for draft, this happens when editing starts), while a lock dependent lets children lock by _Travel, pointing back to the root. In a managed business object the framework sets the enqueue lock automatically; in an unmanaged one you implement the lock method yourself. With draft, the lock is held for the whole draft lifetime, from Edit until Activate or Discard.

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.