ERPClimb logoERPClimb
Behavior Definitions
RAP / CDS / ODataintermediate 10 min read

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

Free sample lesson · open to everyone

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.

In this lessonShow sections

Expert visual walkthrough

RAP · CDS · ODATA ACADEMY · Architecture hierarchyERPClimb.com

Reading a BDEF as the BO Contract

Behavior Definitions · Chapter-specific technical teaching map

Architecture hierarchy

1Top level

Root behavior definition

2Related level

Operations and field rules

3Related level

Lock and authorization

4Related level

Implementation contract

Tutor's chapter 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.

In a real project

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…

Watch out for

• 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…

Conceptual study map, not an SAP configuration screenshot or a guaranteed runtime sequence. Consult the lesson for implementation prerequisites and exceptions.

The situation: a 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.

Explanation

The BDEF is the business object's contract, and RAP enforces it before your code even runs. It's read in order — header, then entity header, then body. When an operation is missing from a BDEF, such as no delete, that's typically deliberate rather than an oversight. New objects should always use strict ( 2 ).

This series covers the behavior definition, written in Behavior Definition Language (BDL), as a syntax guide, with the Managed RAP series showing the same elements used in a full build. Part 1, this lesson, covers reading a BDEF as the BO contract; Part 2 covers CRUD, field control, numbering, locking and authorization syntax; Part 3 covers actions, functions, determinations and validations syntax; Part 4 covers associations, compositions and draft declarations; and Part 5 covers projection and interface BDEFs, strict mode and stable contracts.

Calling the BDEF a "contract" is deliberate: it states what the business object can do and under what conditions — which operations exist, which fields may be changed, how instances are locked, numbered and authorized, and which rules run automatically. RAP enforces all of this before your code ever runs, so a request for an operation that isn't declared never even reaches your implementation. That's exactly why a good BDEF ends up making the implementation smaller.

A BDEF has three levels. The header, at the top of the file and appearing once, declares the implementation type and class — something like "managed implementation in class zbp_r_purchreq unique;" (or unmanaged, projection, interface) — along with "strict ( 2 );" for the strictest syntax checks, always used for new development, and "with draft;" if draft is enabled for the whole business object.

The entity header appears once per entity, starting with something like "define behavior for ZR_PurchReq alias PurchaseRequest." Here, alias gives a short name used in EML and handler method names; persistent table and draft table say where data is stored, for managed scenarios; lock master or lock dependent by _Assoc defines locking; authorization master (global, instance) or authorization dependent by _Assoc defines authorization; etag master Field or total etag Field defines versioning; early numbering or late numbering apply when you number instances yourself; and implementation in class … optionally puts one entity's code into its own class.

The entity body, inside braces, is where the real behavior lives. Standard operations like create;, update; and delete; can each take options in parentheses. Field characteristics are declared with statements like field ( readonly ) … or field ( mandatory ) …. Association operations look like association _Item { create; }. Business logic comes from determination, validation, action, function, determine action and side effects declarations. Draft actions appear if "with draft" is set. And mapping for <table> { CDS field = column; } maps CDS field names to table columns.

A fast way to read an unfamiliar BDEF in about five minutes: check the header first — managed or unmanaged, draft or not, strict level; check the root entity header for where locks, authorization and ETag are defined; note which operations are declared, and which are conspicuously missing, such as no delete; note which fields are read-only or mandatory; note which determinations, validations and actions exist and what triggers them; and finally look at the children — how they're locked and authorized, and whether they can only be created through the parent. The annotated example in the code shows every line along with its meaning.

BDEF and code connect directly: every determination, validation, action, authorization and feature-control declaration becomes a method in the behavior pool. In ADT, placing the cursor on the element and pressing Ctrl+1 generates the method, and F2 on a keyword brings up the ABAP keyword documentation, which is the most reliable reference for your specific release.

After Part 1 you can read any BDEF and explain exactly what the business object allows. Part 2 goes through the syntax options for 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 { /* ... */ }}

Watch out

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.

Do this

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.

In the interview

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

0 of 3 questions attempted

Question 1 of 3

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

Practise this in an interview

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

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

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

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: Reported Without Failed — a Validation That Warns But Never Blocks →

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.