Managed RAP Part 4: Compositions, Create-by-Association and Draft
Preview · a free account unlocks the full lesson
Understand the composition tree behind a RAP business object, create items through their parent with create-by-association and %cid ref, and enable draft so users can edit requests over a longer session safely.
In this lessonShow sectionsHide sections
Visual overview
Explanation
Items can only be created through the parent, declared with association _Item { create; }. Enabling draft requires several pieces together: with draft, draft tables, a total etag, draft actions, and "with draft" added to the relevant associations. Code should always use %tky so it works correctly for both draft and active instances, and draft tables need to be regenerated after adding any new fields.
The Purchase Request already has numbering, locking, authorization and a workflow by this point. This part looks closely at the header-item relationship created in Part 1, covers how to create items correctly, and enables draft — the feature that makes a RAP app behave like a real Fiori application.
A RAP business object isn't a single table; it's a tree of entities. The root, PurchaseRequest, owns its children, the Items. This ownership has to be declared on both sides. In the root CDS view, it's "composition [0..*] of ZR_PurchReqItem as _Item." In the child CDS view, it's "association to parent ZR_PurchReq as _Request on ...".
Composition brings several things along with it: lifecycle, meaning deleting a request automatically deletes its items; locking, via "lock dependent by _Request," so editing an item locks the whole request; authorization, via "authorization dependent by _Request," so item operations are checked against the parent; draft, meaning the whole tree is drafted and activated together; and one transaction, meaning header and items are saved in a single LUW, all or nothing.
Composition should only be modeled when the child truly belongs to the parent — a request item belongs to its request, but a supplier doesn't belong to a request, which is why that relationship is a normal association instead.
Deeper trees are allowed, such as root to item to schedule line, with every level using association to parent, and lock/authorization dependency pointing back to the root through the whole chain.
Items have no standalone "create" operation in the BDEF — they can only be created through the parent, via "association _Item { create; }," which guarantees every item always gets a valid parent key. In EML this is written as CREATE BY \_Item.
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
Interview questions on this topic
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.