ERPClimb logoERPClimb
Unmanaged RAP
RAP / CDS / ODataintermediate 15 min read

Unmanaged RAP Part 1: When to Use It — Locks, Numbering and Messages

Free sample lesson · open to everyone

Key takeaway

Understand when unmanaged RAP is the right choice, exactly which responsibilities move from the framework to you, and implement the first three: locking, key numbering and translating legacy errors into RAP messages.

In this lessonShow sections

The situation: a real project scenario

A company wanted a Fiori app for its 15-year-old custom purchase request transaction. The transaction's function group contained approval-limit checks, budget reservation and change documents. A first attempt used managed RAP on the same tables — and silently skipped all of that logic, so requests created in the new app had no budget reservation.

The team switched to unmanaged RAP. The handler methods collected changes in a buffer, and the saver called the existing function modules, so every old rule ran again. Two details made it production-grade: the lock method reused the same lock object as the old transaction (so a user in the classic screen and a user in Fiori could not edit the same request), and the BAPIRET2 messages were mapped one-to-one with their original message class and number, so the support team recognized every error immediately.

Explanation

Unmanaged RAP means you implement the buffer, CRUD, read, lock, numbering and saver yourself. It's worth reaching for only when legacy logic absolutely must control editing — otherwise, unmanaged save is usually the better fit. The lock method relies on an enqueue lock object on the root key, and every rejection needs both a FAILED entry and a REPORTED message that's actually clear to the user.

This series assumes you already know the managed flow from the Managed RAP series Parts 1-3 — BDEF, handler methods, EML, FAILED/REPORTED/MAPPED — and reuses the same Purchase Request example so the two approaches can be compared line by line. The key difference here is that an existing application layer, referred to below as "the legacy API," already creates, changes and deletes purchase requests, with years of business rules built into it, and that logic must not be bypassed.

Managed RAP assumes the framework can write your tables directly, which is the wrong assumption when an existing API has to stay the single owner of the data, so its checks, change documents, follow-on postings and user exits keep running; when the data isn't sitting in simple tables you own, for example because it lives behind a BAPI, spans several systems, or needs complex persistence logic; or when you're wrapping a brownfield application with a RAP service without rewriting it.

If all you actually need is extra work at save time — a change log, an extra table, an event — you probably don't need full unmanaged at all; "managed with additional save" and "managed with unmanaged save," covered in Part 5, are usually enough.

The rule of thumb is: greenfield development with your own tables calls for managed, while existing business logic that must remain authoritative calls for unmanaged.

Several responsibilities move from the framework to you in unmanaged RAP. The transactional buffer is yours to maintain, keeping created, changed and deleted instances in your own buffer class until save. Create, update, delete, read, create-by-association and read-by-association all become handler methods you implement yourself, covered in Part 3. Locking becomes your own lock method, built on a lock object.

Numbering means assigning keys to new instances yourself. The save sequence becomes your own saver class, with finalize, check_before_save, save and cleanup, covered in Part 4. And you're responsible for translating the legacy API's own messages into RAP messages.

What RAP still provides, even in unmanaged mode, is the BDEF contract, EML, the service and OData layer, authorization and feature-control hooks, ETag checks built on your read method, draft support, and the orchestration of phases — and you still must never call COMMIT WORK yourself, since the framework still owns the LUW.

On locking: declaring "lock master" in an unmanaged BDEF means RAP calls your lock method before any change. You set an exclusive lock using a lock object — created, for example, as EZPR_HEAD on table ZPR_HEAD via ADT or SE11 — and cl_abap_lock_object_factory works for this in both classic and ABAP Cloud development.

If the lock is already held by someone else, report the instance in FAILED along with a message naming the user; RAP releases locks automatically at the end of the transaction, so you never dequeue manually.

If the legacy API sets its own locks, reuse that same lock object so old transactions and the new RAP app correctly block each other.

On numbering, the options mirror managed RAP but put more of the work on you. Early numbering, declared with "early numbering" and implemented via earlynumbering_create, has you assign the key during the interaction phase and return %cid mapped to the key in MAPPED — this suits UUIDs, or cases where the legacy API can hand you a number immediately.

Late numbering, declared with "late numbering," has you assign the final key inside the saver's adjust_numbers method during save — this suits cases where the legacy API only returns the real document number once it actually saves, which is typical for BAPIs creating documents; until then, RAP works with a preliminary ID, %pid.

In this series, the technical key is a UUID assigned via early numbering, while the human-readable RequestID comes back from the legacy API only at save time.

On messages, legacy APIs typically return BAPIRET2 tables or raise exceptions, but RAP needs messages organized per instance in REPORTED, with failed instances listed in FAILED.

The mapping works like this: any message of type E or A becomes a FAILED entry for that instance plus an error message in REPORTED; types W, I and S become warning, information or success messages in REPORTED only.

Using new_message( id number severity v1–v4 ) keeps the original message class and number intact, so users and support see exactly the same message text as in the old transaction. Legacy messages should never be collapsed into one generic "save failed" text — the per-instance, per-field detail is exactly what makes RAP UIs usable.

To put this into practice: create the lock object EZPR_HEAD, with primary key REQUEST_UUID, for table ZPR_HEAD; create the BDEF with "unmanaged implementation in class zbp_r_purchreq_u unique;" (the full BDEF comes in Part 2); implement lock and earlynumbering_create as shown in the code example; and build a reusable helper method that converts a BAPIRET2 table into REPORTED and FAILED entries, which gets reused in Parts 3 and 4.

After Part 1, the three responsibilities easiest to forget in unmanaged RAP — locks, keys and messages — are handled. Part 2 sets up the complete architecture: CDS views, the full BDEF and the buffer class.

Expert unmanaged RAP lab

RAP · UNMANAGED IMPLEMENTATION · PART 1ERPClimb.com

What the developer owns in unmanaged RAP

Design decision · locks, numbering and messages

Developer-owned behavior

Transactional buffer

Own state for create/update/delete and read-your-writes.

RAP framework still provides

Runtime contract

Controls the BO runtime and its transaction boundary.

Step 1

Unmanaged BDEF

Declares operations that the implementation must supply.

Step 2

Behavior pool

Delegates to existing business logic and application buffer.

Always return meaningful errorsIf a lock fails or a legacy service rejects data, report the failed instance and an actionable message; don't silently accept the request.
SAP RAP implementation concepts with fictional object names. Validate API contracts, availability and transaction restrictions for your ABAP release.

Code example

ABAP Code
// ===== BDEF header (unmanaged) =====unmanaged implementation in class zbp_r_purchreq_u unique;   // "unmanaged" hands persistence to your own ABAP code instead of RAP's default SQLstrict ( 2 ); define behavior for ZR_PurchReqU alias PurchaseRequestlock master                                    // this entity owns the enqueue lock; dependent entities reuse it instead of locking separatelyauthorization master ( global, instance )      // this entity performs its own authority checks (vs. deferring to a parent)etag master LocalLastChangedAt                 // field RAP compares to detect concurrent changes (optimistic locking / If-Match)early numbering{  create; update; delete;  association _Item { create; }  field ( readonly ) RequestUUID, RequestID, LocalLastChangedAt;} " ===== Lock method =====  METHOD lock.    TRY.        DATA(lock) = cl_abap_lock_object_factory=>get_instance( iv_name = 'EZPR_HEAD' ).      CATCH cx_abap_lock_failure INTO DATA(lock_error).        RAISE SHORTDUMP lock_error.   " lock object missing = technical error    ENDTRY.     LOOP AT keys ASSIGNING FIELD-SYMBOL(<key>).      TRY.          lock->enqueue( it_parameter = VALUE #(                           ( name = 'REQUEST_UUID' value = REF #( <key>-RequestUUID ) ) ) ).        CATCH cx_abap_foreign_lock INTO DATA(foreign_lock).          APPEND VALUE #( %tky = <key>-%tky ) TO failed-purchaserequest.          APPEND VALUE #( %tky = <key>-%tky                          %msg = new_message_with_text(                                   severity = if_abap_behv_message=>severity-error                                   text     = |Request is being edited by { foreign_lock->user_name }| ) )            TO reported-purchaserequest.        CATCH cx_abap_lock_failure INTO lock_error.          RAISE SHORTDUMP lock_error.      ENDTRY.    ENDLOOP.    " No dequeue: RAP releases locks at the end of the transaction  ENDMETHOD. " ===== Early numbering: assign UUID keys to new instances =====  METHOD earlynumbering_create.    LOOP AT entities INTO DATA(entity).      TRY.          APPEND VALUE #( %cid        = entity-%cid                          RequestUUID = cl_system_uuid=>create_uuid_x16_static( ) )            TO mapped-purchaserequest.        CATCH cx_uuid_error.          APPEND VALUE #( %cid = entity-%cid ) TO failed-purchaserequest.      ENDTRY.    ENDLOOP.  ENDMETHOD. " ===== Helper: legacy BAPIRET2 messages -> RAP FAILED / REPORTED =====  METHOD map_messages.   " IMPORTING tky, return TYPE bapiret2_t; CHANGING failed, reported    LOOP AT return INTO DATA(ret).      DATA(severity) = SWITCH if_abap_behv_message=>t_severity( ret-type                         WHEN 'E' OR 'A' THEN if_abap_behv_message=>severity-error                         WHEN 'W'        THEN if_abap_behv_message=>severity-warning                         WHEN 'S'        THEN if_abap_behv_message=>severity-success                         ELSE                 if_abap_behv_message=>severity-information ).       APPEND VALUE #( %tky = tky                      %msg = new_message( id       = ret-id                                          number   = ret-number                                          severity = severity                                          v1 = ret-message_v1 v2 = ret-message_v2                                          v3 = ret-message_v3 v4 = ret-message_v4 ) )        TO reported-purchaserequest.       IF ret-type CA 'EA'.        APPEND VALUE #( %tky = tky ) TO failed-purchaserequest.    " E/A severity also fails the whole operation, not just a message      ENDIF.    ENDLOOP.  ENDMETHOD.

Watch out

Common mistakes

  • Choosing unmanaged for a greenfield object with its own tables — you then rewrite everything the framework would have done for free.
  • Choosing managed for data that an existing API must own, silently bypassing its business rules.
  • Forgetting the lock method, or using a different lock object than the legacy transaction, so both can edit in parallel.
  • Calling DEQUEUE manually — RAP releases locks at the end of the transaction.
  • Mapping all legacy messages to one generic error, losing message class, number and field context.
  • Reporting a message with severity error but not adding the instance to FAILED (or the reverse).
  • Assuming COMMIT WORK is allowed because "unmanaged means I own everything" — the framework still owns the LUW.

Do this

Best practices

  • Decide managed vs unmanaged by who must own persistence, not by habit.
  • Reuse the legacy application's lock object in the RAP lock method.
  • Use early numbering with UUIDs for technical keys; use late numbering when the legacy API assigns the real number at save.
  • Keep original message class and number when mapping BAPIRET2 → RAP messages.
  • Build the message-mapping helper once and reuse it in every handler and the saver.
  • Use cl_abap_lock_object_factory rather than calling ENQUEUE function modules directly, so the code is cloud-ready.

In the interview

Interview angle

Frequent questions: "When would you use unmanaged RAP?", "What do you have to implement yourself in unmanaged?", "How is locking done in unmanaged RAP?", "How do you handle BAPI messages in RAP?"

Strong answer: unmanaged is for cases where existing business logic or an existing API must remain the owner of persistence, typical in brownfield wrapping. The developer implements the transactional buffer, CRUD and read methods, lock method, numbering and the saver phases; RAP still provides the contract, EML, services, ETag and draft orchestration, and still owns the LUW. Mention late numbering with adjust_numbers when the real document number is only known at save, and mapping BAPIRET2 to REPORTED/FAILED per instance with the original message class.

Practice this lesson

Quick check

0 of 3 questions attempted

Question 1 of 3

Which situation is the strongest reason to implement a RAP business object as unmanaged?

Practise this in an interview

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

1When would you choose unmanaged RAP instead of managed RAP, and what do you have to implement yourself once you do?

2How do you implement locking in unmanaged RAP, and what should happen when another user already holds the lock?

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

Referenced SAP objects

Reviewed reference pages for the objects this page mentions.

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.