ERPClimb logoERPClimb
Unmanaged RAP
RAP / CDS / ODataadvanced 17 min read

Unmanaged RAP Part 3: Create, Update, Delete and Read Handlers

Preview · a free account unlocks the full lesson

Key takeaway

Implement the unmanaged handler methods correctly: create into the buffer, partial updates with %control, delete including the create-then-delete case, a buffer-aware read method, and create-by-association for items.

In this lessonShow sections

Visual overview

Unmanaged RAP Part 3: Create, Update, Delete and Read Handlers — learning sheetFlow: Implement create, update, delete and read in lhc_PurchaseRequest as in the code example → Implement cba_Item and rba_Item (read items of a request: buffer items plus database items, minus deleted) → Implement update, delete, read and rba_Request in lhc_Item following the same patterns → Test with EML: create + update only Description in a second MODIFY, then READ and check that CurrencyCode survived. Create and delete in the same transaction and check the buffer is empty. Key ideas: CREATE; UPDATE AND %CONTROL — THE MOST IMPORTANT DETAIL IN UNMANAGED RAP; DELETE; READ — THE BUFFER-AWARE READ. Watch out: Handlers never write to the database — only the saver does.ERPClimb.com / RAP / LESSON 3/5 / LEARNING SHEETUnmanaged RAP Part 3: Create, Update, Delete and ReadHandlers1 · HOW IT FLOWS1Implementcreate, update,delete and read…2Implementcba_Item andrba_Item (read…3Implementupdate, delete,read and…4Test with EMLcreate + update onlyDescription in a second…2 · KEY IDEAS EXPLAINEDCreateThe key was already assigned byearlynumbering_create (Part 1), so create onlybuilds the row, sets defaults and admin fields…Update And %Control — The Most Important…OData updates are usually PATCH: the client sendsonly the fields that changed. RAP passes the fullentity structure, with the unsent fields empty. If…DeleteIf the instance was created in this sametransaction (flag C), just remove it and its itemsfrom the buffer — the legacy API never needs to…Otherwise mark it D. The saver will call thelegacy delete, which is responsible for thedependent items.Read — The Buffer-Aware ReadRAP calls read for EML READ ENTITIES, for ETagchecks before an update, and to return results ofactions. Always use get_head so uncommitted…3 · REMEMBER · WATCH OUTRememberCreate: assign keys, fill MAPPED with %cid → key, store in buffer.Update: apply only fields flagged in %control (partial update).Delete and read: work on the buffer first.!Watch outHandlers never write to the database— only the saver does.4 · IN A REAL PROJECTAn unmanaged wrapper for a custom asset register went live, and within a day users reported that editing anasset's description wiped its location, cost center and responsible person. The update handler did"MOVE-CORRESPONDING entity TO db_row" and saved. Fiori sent a PATCH with only the Description field…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

Part 2 gave the BDEF, the behavior pool skeleton, and the buffer class. This part fills in the handler methods, holding to a strict rule throughout: handlers only ever change lcl_buffer, and the legacy API is called exclusively by the saver, covered in Part 4.

Every handler follows a consistent signature pattern. The input is either "entities" (for create, update, create-by-association) or "keys" (for delete, read, lock, actions), and it's always a table — every row has to be processed, never just the first one assumed.

The output includes MAPPED, carrying new keys for each %cid; FAILED, carrying instances that failed along with %fail-cause; and REPORTED, carrying messages — with read methods also returning RESULT. %cid is the client's temporary ID for a new instance, while %tky is the transactional key of an existing one. %fail-cause tells RAP and the OData layer exactly why something failed: not_found maps to 404, unauthorized to 403, and there's also locked, conflict, and unspecific.

Create is comparatively simple here, since the key was already assigned by earlynumbering_create back in Part 1: create only builds the row, sets its defaults and admin fields, and inserts it into the buffer with flag C — it never calls the legacy API directly. Mandatory-field and business checks belong in validations or check_before_save rather than here, because a UI may legitimately create an empty draft first.

Update, and specifically %control, is the single most important detail in unmanaged RAP. OData updates are usually PATCH requests, where the client only sends the fields that actually changed, but RAP passes the full entity structure regardless, with the unsent fields left empty — so copying the whole structure onto the existing row would overwrite every unsent field with blank. %control is what prevents this: for each field, entity-%control-<Field> is set to if_abap_behv=>mk-on only when the client actually sent that field.

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.