ERPClimb logoERPClimb
Draft Handling
RAP / CDS / ODataintermediate 9 min read

Draft Handling Part 1: Draft Architecture — Active Data and Draft Persistence

Free sample lesson · open to everyone

Key takeaway

Understand how RAP draft works under the hood: active and draft instances, draft tables, %is draft and IsActiveEntity, draft administrative data, and what the framework does for you.

In this lessonShow sections

The situation: a real project scenario

Users of a non-draft purchase request app lost their input several times a week: long item lists were entered, then a session timeout or accidental browser refresh discarded everything. Validation errors also appeared only at the very end, after twenty minutes of typing.

Enabling draft changed the experience: every field change was stored immediately, users could leave and continue later from any device, calculated totals appeared while typing, and errors surfaced when they clicked Save via Prepare instead of after a failed submit. The number of "lost data" tickets dropped to zero.

Explanation

This series covers draft across five parts: this lesson covers draft architecture; Part 2 covers the draft lifecycle — create, edit, resume, activate, discard; Part 3 covers draft locking, ETags and concurrency; Part 4 covers validations, determinations and side effects in draft; and Part 5 covers troubleshooting draft incidents. Managed RAP Part 4, which covers enabling draft, is the prerequisite here.

Draft exists because web apps are fundamentally stateless — each request stands on its own — while users actually edit complex objects over minutes or hours, get interrupted, and switch devices. Without draft, unsaved input would simply be lost, and the data could only be checked once the user finally clicked Save.

Draft instead stores every change immediately in a draft copy, so nothing gets lost, determinations can react while the user is still typing (on modify), the object is protected from other editors, and the active data only actually changes once the user activates, which is effectively the save.

Every instance can exist in two versions. The active instance is the real business data sitting in the persistent tables, such as zpr_head. The draft instance is the work-in-progress copy living in the draft table, such as zpr_head_d.

Both share the same key, distinguished only by a draft indicator: in ABAP and EML, that's %is_draft, set to if_abap_behv=>mk-on for draft or mk-off for active, as part of %tky; in OData, it's the key containing IsActiveEntity=true or false. A brand-new object starts out as draft only, while an existing object only gets a draft once the user clicks Edit.

Draft tables come one per entity, generated by the ADT quick fix from the BDEF with something like "draft table zpr_head_d". Each one contains all the fields of the entity plus an include carrying draft administrative fields — the "draft admin include" — covering things like who created the draft and when it was last changed.

The framework reads and writes these draft tables; the code never does. It's worth remembering to regenerate the draft table after adding a field to the CDS entity, since otherwise activation fails with field-mismatch errors.

Draft administrative data is metadata the framework keeps per draft — the owner, when it was created, when it was last changed, who's currently working on it — and Fiori uses this to show things like "Draft," "Locked by …" and "Unsaved changes by …" without any of it being maintained by hand.

The framework takes care of quite a lot on its own: it stores every change to a draft instance in the draft tables; it handles the draft actions Edit, Activate, Discard, Resume and Prepare; it copies the draft into active data on activation, running the full save sequence, and deletes the draft afterward; it manages the exclusive lock on the active instance for as long as a draft exists, covered in Part 3; and it routes EML and OData requests to either draft or active data based on %is_draft or IsActiveEntity.

What's left to actually do is to declare draft in the BDEF, following the checklist in Behavior Definitions Part 4; use %tky everywhere in handler code rather than a plain key; and choose between on modify and on save for determinations, listing validations under Prepare, as covered in Part 4. With that, it becomes possible to explain exactly what happens in the database when a user edits a purchase request with draft enabled.

Expert draft handling walkthrough

Draft handling · Part 1ERPClimb.com

Active and draft are distinct persisted states

Active persistence

Travel 5001 · Status = OPEN

IsActiveEntity = true

Draft persistence

Travel 5001 · Status = REVIEW

IsActiveEntity = false

Which version does EML read?

The user edits a persisted draft copy while the active version remains OPEN until activation. Use %tky with %is_draft to address the intended state.

Illustrative RAP draft state and actions; behavior varies with implementation and ABAP release.

Code example

ABAP Code
// ===== Draft enablement (base BDEF) - summary =====managed implementation in class zbp_r_purchreq unique;strict ( 2 );                                      // enforces RAP's strictest consistency checks at design timewith draft;                                        // draft for the whole BO define behavior for ZR_PurchReq alias PurchaseRequestpersistent table zpr_head                          // ACTIVE datadraft table zpr_head_d                             // DRAFT data (generated)lock mastertotal etag LastChangedAt                           // concurrency check field covering the whole draft/active pairauthorization master ( global, instance )etag master LocalLastChangedAt{  create; update; delete;  association _Item { create; with draft; }  draft action Edit; draft action Activate optimized;     // Edit = start/continue editing a draft; Activate = save draft into active data  draft action Discard; draft action Resume;               // Discard = delete the draft; Resume = reopen an existing draft  draft determine action Prepare { }                        // runs validations before Activate; implemented in the behavior class} " ===== Draft vs active in EML: the difference is %is_draft inside %tky =====READ ENTITIES OF zr_purchreq  ENTITY PurchaseRequest ALL FIELDS  WITH VALUE #( ( RequestUUID = uuid  %is_draft = if_abap_behv=>mk-on  ) )   " draft copy  RESULT DATA(draft_version). READ ENTITIES OF zr_purchreq  ENTITY PurchaseRequest ALL FIELDS  WITH VALUE #( ( RequestUUID = uuid  %is_draft = if_abap_behv=>mk-off ) )   " active data  RESULT DATA(active_version). " ===== The same in OData =====" GET .../PurchaseRequest(RequestUUID=<uuid>,IsActiveEntity=false)   -> draft" GET .../PurchaseRequest(RequestUUID=<uuid>,IsActiveEntity=true)    -> active " ===== What the tables contain while a user edits request 4711 =====" zpr_head    : 4711, 'Office chairs',        status N   (unchanged)" zpr_head_d  : 4711, 'Ergonomic office chairs', status N  + draft admin fields" -> after Activate: zpr_head updated, zpr_head_d row deleted

Watch out

Common mistakes

  • Thinking draft is only a Fiori UI feature — it is a backend persistence concept.
  • Writing to or reading from draft tables directly.
  • Using key fields instead of %tky, so code works on the wrong version.
  • Forgetting to regenerate draft tables after adding fields.
  • Enabling draft in API services where clients do not need it.

Do this

Best practices

  • Enable draft for UI scenarios with complex or long edits.
  • Always use %tky; test every handler with draft and active instances.
  • Let the framework manage draft tables and admin data.
  • Regenerate draft tables whenever the entity structure changes.
  • Keep APIs without draft (separate projection).

In the interview

Interview angle

Questions: "What is draft in RAP and why is it needed?", "How are draft and active instances distinguished?", "Where is draft data stored?"
Strong answer: draft stores unfinished changes persistently for stateless web apps; each instance can exist as active and draft, distinguished by %is_draft in %tky (IsActiveEntity in OData); draft data lives in framework-managed draft tables with an admin include; activation runs the save sequence, copies draft to active and deletes the draft. Code must use %tky.

Practice this lesson

Quick check

0 of 3 questions attempted

Question 1 of 3

Where is the draft table of a RAP entity declared?

Practise this in an interview

Answer in your own words and get instant feedback, the way an interviewer would judge it.

1What is draft in RAP, why is it needed, and how are draft and active instances distinguished?

2When would you enable draft for a RAP BO, and when not?

Try a related Code Lab

This published exercise covers the same SAP topic. Apply the ideas in a hands-on scenario, then return to review your answers.

Open: Missing Ownership Check Lets One User Edit Another User's Draft →

See it in code

Each example starts from a requirement, shows the design, then the code step by step with a plain-language explanation of every part.

Was this lesson helpful?

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.