ERPClimb logoERPClimb
CDS Associations
RAP / CDS / ODataintermediate 8 min read

CDS Associations Part 4: Associations vs Compositions in a RAP Business Object

Preview · a free account unlocks the full lesson

Key takeaway

Understand the CDS side of a RAP business object tree: composition vs association, "association to parent", and how projections redirect compositions, parents and normal associations.

In this lessonShow sections

Visual overview

CDS Associations Part 4: Associations vs Compositions in a RAP Business Object — learning sheetFlow: In ZR_PurchReq, declare the composition to ZR_PurchReqItem → In ZR_PurchReqItem, declare association to parent → Activate both together (they depend on each other) → In ZC_PurchReq and ZC_PurchReqItem, redirect the composition and the parent. Key ideas: THE DIFFERENCE; THE ROOT SIDE; THE CHILD SIDE; PROJECTIONS: REDIRECT EVERYTHING. Watch out: Only use composition inside one business object — never to another BO.ERPClimb.com / RAP / LESSON 4/5 / LEARNING SHEETCDS Associations Part 4: Associations vs Compositions in aRAP Business Object1 · HOW IT FLOWS1In ZR_PurchReq,declare thecomposition to…2InZR_PurchReqItem,declare…3Activate bothtogether (theydepend on each…4In ZC_PurchReqandZC_PurchReqItem…2 · KEY IDEAS EXPLAINEDThe DifferenceAssociation: two entities are related, each hasits own lifecycle. A sales order refers to acustomer; deleting the order does not delete the…Composition: the child is part of the parent. Apurchase request item exists only within itsrequest; deleting the request deletes the items…The Root SideNo ON condition — it is derived from the child's"association to parent".Cardinality usually [0..*] or [1..*].The Child SideThe child must contain the parent's key field(RequestUUID).A deeper child (e.g. schedule line under item)declares "association to parent" to theitem and usually an extra association to the root…Projections: Redirect Everything_Item : redirected to composition childZC_PurchReqItem_Request : redirected to parent ZC_PurchReq3 · REMEMBER · WATCH OUTRememberAssociation = "related to"; composition = "owned by,lives and dies with the parent".Root declares composition [0..*] of Child; child declares associationto parent.Projections must redirect: composition child, parent, and normalassociations.!Watch outOnly use composition inside onebusiness object — never to anotherBO.4 · IN A REAL PROJECTA developer modeled the relationship from a purchase request to its supplier as a composition "becausethe supplier belongs to the request". Activation failed with confusing messages, and after a workaroundthe BDEF tried to lock suppliers together with requests. The review clarified: the supplier has its own…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

Parts 1 through 3 used associations purely for reading. RAP business objects add a second kind of relationship on top of that: the composition. This lesson covers the CDS syntax for it, while RAP Business Objects Part 1 covers the design decision behind it.

An association describes two entities that are related but each have their own lifecycle — a sales order refers to a customer, but deleting the order does not delete the customer. A composition describes a child that is actually part of the parent: a purchase request item exists only within its request, deleting the request deletes the items along with it, and locks, authorization and saves all go through the root.

On the root side, the root view entity ("define root view entity") declares composition [0..*] of ZR_PurchReqItem as _Item. There's no ON condition here, since it's derived from the child's own "association to parent," and the cardinality is usually [0..*] or [1..*].

Free account

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

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.