ERPClimb logoERPClimb
RAP Business Objects
RAP / CDS / ODataintermediate 10 min read

RAP Business Objects Part 1: Designing the BO — Root, Children and Boundaries

Free sample lesson · open to everyone

Key takeaway

Design a RAP business object before writing code: what one BO is, how to choose the root, which data belongs in the composition tree, which data is only referenced, and how keys and naming follow from that.

In this lessonShow sections

Expert visual walkthrough

RAP · CDS · ODATA ACADEMY · Architecture hierarchyERPClimb.com

Designing the BO — Root, Children and Boundaries

RAP Business Objects · Chapter-specific technical teaching map

Architecture hierarchy

1Top level

Root BO boundary

2Related level

Composition children

3Related level

Interface CDS model

4Related level

Projection for consumers

Tutor's chapter takeaway

Design a RAP business object before writing code: what one BO is, how to choose the root, which data belongs in the composition tree, which data is only referenced, and how keys and naming follow from that.

In a real project

A team modeled "Project" as a RAP BO with WBS elements, tasks, time entries and documents all as compositions under the project root. It worked in the demo. In production, every time an employee booked a time entry, the whole…

Watch out for

• Putting every related entity into the composition tree "because it belongs to it". • Modeling a reference (customer, product) as a composition. • Using a normal association where the child really has no life without the…

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 team modeled "Project" as a RAP BO with WBS elements, tasks, time entries and documents all as compositions under the project root. It worked in the demo. In production, every time an employee booked a time entry, the whole project was locked, so project managers could not edit the project for hours, and draft sessions became very large.

In a redesign, time entries and documents became separate BOs with an association to the project, because they have their own lifecycle and editors. The project BO kept only WBS elements and tasks, which really must be consistent with the project header. Lock conflicts disappeared and response times improved.

Explanation

A business object represents one transactional boundary — everything inside it is locked, checked and saved together. Composition should only be used for parts that have no lifecycle of their own; anything else, such as a supplier or a product, belongs as an association instead. Getting this wrong and oversizing the tree leads to lock conflicts and heavy drafts.

This series gives you the map of a RAP business object (BO); the detailed build steps live in the Managed RAP and Unmanaged RAP series, while here you learn the concepts that make those steps make sense. Part 1, this lesson, covers designing the BO — root, children and boundaries; Part 2 covers the managed versus unmanaged decision; Part 3 covers the transactional buffer, the save sequence and the RAP LUW; Part 4 covers locking, ETags and concurrency; and Part 5 covers authorization, feature control and messages.

A RAP business object is a real-world thing your application manages as one unit — a purchase request, a sales order, a travel booking. Technically, it's a tree of CDS entities plus a behavior definition stating what may happen to that tree. Its most important property is that it forms a transactional boundary: everything inside the tree is locked together, checked together, and saved together, all or nothing.

The tree itself has a root entity, declared with "define root view entity," acting as the anchor — its key identifies the whole BO instance, and locks, the ETag master and the authorization master usually sit here.

Child entities are parts that belong to the root and cannot exist without it, such as items, schedule lines or notes, declared with "composition" in the parent and "association to parent" in the child. Deeper levels are allowed too, such as root to item to schedule line.

Anything outside the tree — a customer, a material, a currency, another business object — is only referenced through a normal association.

Deciding what belongs in the tree comes down to asking, for each candidate entity: does it have its own lifecycle — if it can be created, changed or deleted independently, like a customer or a product, it's a separate BO and should be referenced rather than included; must it stay consistent with the root within the same transaction — if an item change must be validated together with the header, say for totals or status, it belongs in the tree; who edits it and when — if two different teams edit it at different times, putting it in the tree forces unnecessary locking of the whole BO; and how big can it get — a tree with thousands of children per root makes every lock and draft heavy, which is a sign to consider a separate BO instead.

The rule of thumb is to keep the tree as small as consistency actually requires.

On keys: use a technical UUID key for every entity, generated by the framework in managed RAP; children carry the parent's key as a foreign key field, such as RequestUUID in the item; and it's worth adding a human-readable semantic number on the root, such as RequestID, for users to work with, a topic covered in Managed RAP Part 2.

A consistent naming scheme makes every RAP project easier to navigate: tables might be named ZPR_HEAD and ZPR_ITEM, plus draft tables added later; BO base views might be ZR_PurchReq for the root and ZR_PurchReqItem for the child, with a behavior definition named ZR_PurchReq; the behavior pool might be ZBP_R_PURCHREQ; projections per consumer might use ZC_ for UI and ZA_, or similar, for APIs; and the service definition might be named ZUI_… or ZAPI_…, with its binding carrying an _O4 suffix.

Designing before coding means: writing down the business object in one sentence, such as "A purchase request with its items, approved as one unit"; listing candidate entities and applying the four questions above; drawing the tree — root, children, references; deciding on keys, a UUID plus a semantic number; deciding the implementation type, covered in Part 2; and only then creating tables and CDS views, as covered in Managed RAP Part 1.

After Part 1 you have a method for drawing a correct BO tree, and the code example shows how such a design is expressed in CDS and in the first lines of a behavior definition.

Code example

ABAP Code
// ===== Design: Purchase Request BO =====////   PurchaseRequest (root, ZR_PurchReq)          <- locks, ETag, authorization here//     └── Item (child, ZR_PurchReqItem)          <- composition: lives and dies with the request////   References (NOT in the tree - own lifecycle)://     Supplier  -> association to I_Supplier//     Currency  -> association to I_Currency//     Product   -> association to I_Product // ===== Root view: composition + references =====define root view entity ZR_PurchReq  as select from zpr_head  composition [0..*] of ZR_PurchReqItem as _Item                         // owned  association [0..1] to I_Supplier as _Supplier    on $projection.Supplier = _Supplier.Supplier                          // referenced  association [0..1] to I_Currency as _Currency    on $projection.CurrencyCode = _Currency.Currency                      // referenced{  key request_uuid  as RequestUUID,      request_id    as RequestID,      supplier      as Supplier,      currency_code as CurrencyCode,      _Item,      _Supplier,      _Currency} // ===== Child view: back-link to the parent =====define view entity ZR_PurchReqItem  as select from zpr_item  association to parent ZR_PurchReq as _Request                          // "to parent": lets RAP inherit the root's lock/auth for this child    on $projection.RequestUUID = _Request.RequestUUID{  key item_uuid   as ItemUUID,      parent_uuid as RequestUUID,      item_no     as ItemNo,      _Request} // ===== The tree in the behavior definition =====managed implementation in class zbp_r_purchreq unique;   // generated handler class; "unique" = the only implementing class for this BOstrict ( 2 );                                             // enables RAP's strict consistency checks, recommended for all new BOs define behavior for ZR_PurchReq alias PurchaseRequestpersistent table zpr_headlock masterauthorization master ( global, instance )etag master LocalLastChangedAt{  create; update; delete;  association _Item { create; }        // children only via the parent} define behavior for ZR_PurchReqItem alias Itempersistent table zpr_itemlock dependent by _Request             // locked with the rootauthorization dependent by _Request    // checked on the rootetag master LocalLastChangedAt{  update; delete;  association _Request;}// Full, compiling version: Managed RAP Part 1.

Watch out

Common mistakes

  • Putting every related entity into the composition tree "because it belongs to it".
  • Modeling a reference (customer, product) as a composition.
  • Using a normal association where the child really has no life without the parent.
  • Designing without a UUID key, then struggling with numbering and draft.
  • Starting with tables and code before drawing the tree.
  • Mixing naming conventions so nobody can tell base views from projections.

Do this

Best practices

  • Treat the BO as a transactional boundary: lock, check and save together.
  • Keep the tree as small as consistency requires; reference everything with its own lifecycle.
  • UUID keys for all entities, a semantic number on the root.
  • Agree a naming convention (ZR_, ZC_, ZBP_, ZUI_) at project start.
  • Draw and review the tree with the functional expert before building.

In the interview

Interview angle

Questions: "What is a RAP business object?", "How do you decide what belongs in the composition tree?", "What is the difference between composition and association?"

Strong answer: a BO is a tree of CDS entities with behavior, forming one transactional boundary; the root carries lock, ETag and authorization master, children depend on it. Include an entity in the tree only if it has no independent lifecycle and must be consistent with the root in one transaction; everything else is referenced via association. Mention the cost of oversized trees (locking, draft size) — a sign of design experience.

Practice this lesson

Quick check

0 of 3 questions attempted

Question 1 of 3

Which entity should be modeled as a composition child of a Purchase Request root?

Practise this in an interview

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

1What is a RAP business object, and how do you decide which entities belong in its composition tree?

2A 'Project' BO contains WBS elements, tasks, time entries and documents as compositions. Project managers constantly get lock errors. How would you redesign it?

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.