Behavior Definitions
RAP / CDS / ODataintermediate

Behavior Definitions Part 1: Reading a BDEF as the BO Contract

Key takeaway

Learn to read any behavior definition line by line: the header, the entity header, and the entity body — and understand the BDEF as the executable contract of a RAP business object.

What this complete series covers

Learn Behavior Definitions in a clear, practical sequence — from the basic idea to real project use, troubleshooting, and interview-ready understanding.

Who it is for
Best for SAP consultants, developers, and learners who want a practical understanding of Behavior Definitions.
Prerequisites
Basic ABAP and ADT in Eclipse are recommended. The series explains the RAP/CDS/OData concepts as they are introduced.
Final outcome
By the end, you should be able to explain Behavior Definitions clearly, follow the main end-to-end flow, apply it in a project scenario, and troubleshoot the most common issues.
  1. Part 1: Behavior Definitions Part 1: Reading a BDEF as the BO Contract

    Read a RAP behavior definition as the executable contract of a business object: implementation type, persistence, locking, authorization, standard operations, custom operations, fi

  2. Part 2: Behavior Definitions Part 2: CRUD, Field Control, Numbering, Locking and Authorization

    Use behavior-definition declarations to make standard operations, field mutability, key numbering, locks, ETags, and authorization part of the RAP contract rather than scattered runtime checks.

  3. Part 3: Behavior Definitions Part 3: Actions, Functions, Determinations and Validations

    Model RAP business behavior with the correct primitive: actions for commands, functions for side-effect-free reads, determinations for automatic derivation, and validations for rul

  4. Part 4: Behavior Definitions Part 4: Associations, Compositions and Draft Declarations

    Control how RAP consumers create and navigate children through compositions, declare association operations intentionally, and enable draft without weakening aggregate ownership.

  5. Part 5: Behavior Definitions Part 5: Projection Behavior, Strict Mode and Stable Contracts

    Use projection behavior to expose only intended capabilities, strict mode to catch contract weaknesses early, and stable public naming/semantics so RAP services survive refactoring and upgrades.

System and release assumptions: Examples target recent SAP S/4HANA / ABAP Cloud capabilities. RAP, CDS, OData, and Fiori Elements syntax and tooling can differ by ABAP platform release.

Explanation

📌 KEY POINTS
✅ The BDEF is the BO contract — RAP enforces it before your code runs.

✅ Header → entity header → body: read it in this order.

✅ Missing operations are deliberate (e.g. no delete).

⚠️ Always strict ( 2 ) for new objects.

▶ WHAT THIS SERIES COVERS
The behavior definition (BDEF) is written in Behavior Definition Language (BDL). This series is the syntax guide; the Managed RAP series shows the same elements in a full build.

  • Part 1 — reading a BDEF as the BO contract (this lesson)
  • Part 2 — CRUD, field control, numbering, locking and authorization syntax
  • Part 3 — actions, functions, determinations and validations syntax
  • Part 4 — associations, compositions and draft declarations
  • Part 5 — projection and interface BDEFs, strict mode and stable contracts

WHY "CONTRACT"
The BDEF states what the business object can do and under which conditions: which operations exist, which fields may be changed, how instances are locked, numbered and authorized, which rules run automatically. RAP enforces this contract before your code runs. A request for an operation that is not declared never reaches your implementation. That is why a good BDEF makes the implementation smaller.

━━━━━━━━━━━━━━━━━━━━
▶ THE THREE LEVELS OF A BDEF

  1. Header (top of the file, once)
  • Implementation type and class: "managed implementation in class zbp_r_purchreq unique;" (or unmanaged, projection, interface).
  • "strict ( 2 );" — strictest syntax checks; always for new development.
  • "with draft;" — draft enabled for the whole BO.
  1. Entity header (one per entity: "define behavior for ZR_PurchReq alias PurchaseRequest")
  • alias — a short name used in EML and handler method names.
  • persistent table / draft table — where data is stored (managed).
  • lock master / lock dependent by _Assoc
  • authorization master ( global, instance ) / authorization dependent by _Assoc
  • etag master Field / total etag Field
  • early numbering / late numbering (when you number yourself)
  • implementation in class … — optional, to put one entity's code into its own class.
  1. Entity body (in braces)
  • Standard operations: create; update; delete; — each can have options in parentheses.
  • Field characteristics: field ( readonly ) …; field ( mandatory ) …; etc.
  • Association operations: association _Item { create; }
  • Business logic: determination, validation, action, function, determine action, side effects.
  • Draft actions (if with draft).
  • mapping for <table> { CDS field = column; } — CDS names to table columns.

━━━━━━━━━━━━━━━━━━━━
▶ HOW TO READ AN UNKNOWN BDEF IN FIVE MINUTES

  1. Header: managed or unmanaged? Draft? Strict?
  2. Root entity header: where are locks, authorization and ETag?
  3. Which operations are declared — and which are missing on purpose (e.g. no delete)?
  4. Which fields are read-only or mandatory?
  5. Which determinations/validations/actions exist, and on which triggers?
  6. Children: how are they locked and authorized; can they be created only via the parent?

The annotated example in the code shows every line with its meaning.

━━━━━━━━━━━━━━━━━━━━
▶ HOW BDEF AND CODE CONNECT

Every determination, validation, action, authorization and feature-control declaration becomes a method in the behavior pool. In ADT, place the cursor on the element and press Ctrl+1 to generate the method; F2 on a keyword shows the ABAP keyword documentation — the most reliable reference for your release.

━━━━━━━━━━━━━━━━━━━━
▶ WHAT YOU HAVE AFTER PART 1

The ability to read any BDEF and explain what the BO allows. Part 2 goes through the syntax options of operations and fields.

Code example

ABAP Code
managed                                   // implementation type (managed / unmanaged / projection / interface)  implementation in class zbp_r_purchreq  // behavior pool with your code  unique;                                  // one pool for this BDEFstrict ( 2 );                             // strictest checks - always for new objectswith draft;                               // draft for the whole BO define behavior for ZR_PurchReq           // root entity (CDS root view entity)  alias PurchaseRequest                   // short name for EML and method namespersistent table zpr_head                 // managed: framework writes heredraft table zpr_head_d                    // draft datalock master                               // exclusive lock on this roottotal etag LastChangedAt                  // checked when activating a draftauthorization master ( global, instance ) // who may do whatetag master LocalLastChangedAt            // stale-data protection{  create;                                 // standard operations  update ( features : instance );         // enabled/disabled by state  delete ( features : instance );  association _Item { create; with draft; }   // items only via the parent   field ( readonly, numbering : managed ) RequestUUID;  // UUID generated  field ( readonly ) RequestID, Status, TotalAmount;    // never set by consumers  field ( mandatory ) Description, CurrencyCode;        // must be filled   determination setInitialStatus on modify { create; }  // automatic derivation  validation validateDescription on save { create; field Description; }  // blocks save  action ( features : instance ) approve result [1] $self;              // explicit step   draft action Edit;  draft action Activate optimized;  draft action Discard;  draft action Resume;  draft determine action Prepare { validation validateDescription; }   mapping for zpr_head                    // CDS name = table column  {    RequestUUID = request_uuid;    RequestID   = request_id;    Description = description;    /* ... */  }} define behavior for ZR_PurchReqItem alias Itempersistent table zpr_itemdraft table zpr_item_dlock dependent by _Request                // locked with the rootauthorization dependent by _Request       // authorized on the rootetag master LocalLastChangedAt{  update;  delete;                                 // no create: only via PurchaseRequest\_Item  association _Request { with draft; }  field ( readonly, numbering : managed ) ItemUUID;  field ( readonly ) RequestUUID;  mapping for zpr_item { /* ... */ }}

Real project scenario

A new developer joined a project with 30 RAP business objects and was asked why the Purchase Request API allowed deleting items but not requests. Instead of reading hundreds of lines of handler code, the lead showed how to read the BDEFs: the request entity had no "delete" declared on purpose, while the item entity did.
The team turned this into an onboarding exercise: for each BO, read the BDEF with the five-minute checklist and write a one-paragraph contract summary. New developers became productive in days, and design reviews started from the BDEF rather than from code.

Common mistakes

  • Reading the handler code to understand a BO instead of the BDEF.
  • Declaring every operation by habit, then blocking unwanted ones in code.
  • Enforcing read-only or mandatory rules in code instead of field characteristics.
  • Forgetting the mapping block when CDS names differ from column names.
  • Omitting strict ( 2 ) in new objects.
  • Allowing children to be created standalone instead of via the parent association.

Best practices

  • Treat the BDEF as the primary design document of the BO.
  • Declare only operations that are valid for the business.
  • Express rules declaratively (field characteristics, features) before writing code.
  • Use aliases that read well in EML and method names.
  • Use F2 keyword documentation in ADT for release-specific syntax details.

Interview angle

Questions: "What is a behavior definition?", "What goes into the entity header vs the body?", "How do BDEF declarations connect to ABAP code?"
Strong answer: the BDEF is the transactional contract in BDL; header defines implementation type, strict mode and draft; entity header defines alias, persistence, lock, authorization, ETag and numbering; the body declares operations, fields, associations, determinations, validations, actions and mapping. RAP enforces it before code runs; each logic element maps to a generated method in the behavior pool.

Practice this lesson

Quick check

1. Why would you create an interface BDEF on top of a RAP business object?

2. What is the fundamental difference between a managed and an unmanaged behavior implementation in a RAP business object?

3. In a RAP behavior definition, what is the purpose of the 'mapping for' addition?

Interview questions

1. You join a project with an unfamiliar RAP BO. How do you understand what it allows in five minutes, just by reading its BDEF?

Answer it in your own words first, then compare.

2. What is a behavior definition, and what goes into its header, entity header and entity body?

Answer it in your own words first, then compare.

Practice more with Interview AI →

Reference-verified: the steps are checked against official SAP documentation and tutorials, and object and field names in the sample code are checked for consistency. The code has not been compiled or run on an SAP system by ERPClimb. Syntax marked release-dependent varies by SAP release, so check it in your own system.

More lessons in this topic

Interview questions on this topic

Related SAP topics