Make ownership explicit with a composition

A purchase request can have several items, and an item should not exist without its request. That ownership relationship is a good reason to model a RAP composition rather than two unrelated entities.

Add the child relationship

define root view entity ZR_PURCHASE_REQUEST
  as select from zpurchase_request
  composition [0..*] of ZI_PURCHASE_REQUEST_ITEM as _Items
{
  key request_id as RequestId,
      _Items
}

The to-many composition describes a parent-child relationship in the CDS model. The child entity needs the corresponding association to its parent, with a matching key condition. The child behavior is defined separately when its operations are needed.

Composition carries lifecycle meaning: child records are dependent on the parent. Do not use it just because two tables can be joined. Cardinality and ownership must match the business rule; these fictional names are not SAP standard objects.

Sources

Developer practice · ABAP

Practice: model dependent request items

Add a to-many composition named _Items from the request root to a fictional item entity.

Complete the task using the syntax and structure described above. Variable names can differ if you use them consistently. This browser checker checks structure only; it does not compile or run ABAP.

0 required structures detected · 0 checks