
Up to now, we worked with RAP Business Objects that consisted of one single node, the root entity. More generally, a business object (BO) consists of a hierarchical tree of nodes where each node is an element that is modeled with a CDS entity and arranged along a composition path.
At runtime, one instance of the BO consists of exactly one instance of the root entity and a variable number of instances of the child entities. A sales order, for example, consists of exactly one header (the root entity instance) and several items (child entity instances).
The hierarchy of entities is defined through two special kinds of associations, namely by Compositions and To-Parent Associations.
Note
It is not necessary to define foreign key relations between the underlying tables. They are included in the picture to illustrate that the associations in the CDS data model correspond to relations in the relational data model on ABAP Dictionary level.

In RAP, a composition is a specialized association that defines a whole-part relationship and always leads from the parent to the direct child. A child entity (composite part) only exists together with its parent entity (whole). The definition of a composition always requires the definition of a corresponding to-parent association that leads from the child entity to the direct parent entity.
In the example, the hierarchy consists of three entities, the root entity (Text), its direct child entity (Line), and an indirect child entity (Word), which has the first child entity as its parent. The text is a composition of text lines and each line is a composition of words. For each of the two compositions, there is a corresponding to-parent association.
And the compositions and to-parent associations, it is possible to define other relations within the composition tree, for example, from a child entity's child to the root entity. Such relations are defined with ordinary associations. They are not mandatory in general, but can be needed in certain circumstances, for example, to establish a lock master/ lock dependent relation over more than two layers.
The following restrictions apply when modeling the composition tree of a RAP Business Objects:
- There is exactly one root entity.
- The root entity may be the source but must not be the target of a composition.
- Source and target of a composition are never the same entity.
The cardinality of an association expresses how many instances of an entity can be involved in the relationship. It specifies the number of entity instances that are connected to a single source instance and is expressed with a lower bound and an upper bound in the form: (lower_bound..upper_bound). In a RAP BO, the cardinality of the composition can be 0..1 or 0..n, but the cardinality of a to-parent association always has to be 1..1.








