Ansicht
Dokumentation

ABENCDS_COMPOSITION_V2 - CDS COMPOSITION V2

ABENCDS_COMPOSITION_V2 - CDS COMPOSITION V2

SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up   SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up  
This documentation is copyright by SAP AG.
SAP E-Book

- CDS View Entity, COMPOSITION

... COMPOSITION $[ [min..max] $] OF target $[AS _compos$] ...

Effect

A CDS composition in ABAP CDS is a specialized CDS association that defines the current CDS view entity as parent entity of the composition target. The composition target is the child entity and it must define a to-parent association to its parent entity. CDS compositions define the CDS composition tree of a RAP business object in the context of the ABAP RESTful Application Programming Model.

A composition is defined in a SELECT statement of a CDS view entity using the keyword COMPOSITION. A CDS composition associates the current CDS entity, as a composition source, with the composition target target specified in the definition of the composition.

The child entity (composition target) must already have a to-parent association to the composition parent before a composition can be defined in the parent.

Rules

CDS compositions are defined similarly to CDS associations. Here are the similarities and differences:

  • Similarities

  • Differences:
  • No ON condition is defined explicitly for a composition. The ON condition is generated automatically using the ON condition of the to-parent association of the composition target.

  • A default filter cannot be defined for a composition. The syntax ... WITH DEFAULT FILTER ... is not allowed.

The following applies to the composition target target:

  • A child entity can be the target of exactly one composition. This means that a child entity can have exactly one parent entity.
  • The target of a composition must not be a root entity.
  • The composition target cannot be specified using a path expression. The following is not allowed:
COMPOSITION OF _path._to_child
  • Self-compositions are not allowed. The target of a composition cannot be the CDS entity in which this composition is defined.

Exposure:

  • The name of the composition _compos must be added exactly once to the select_list of the CDS view entity it is defined in, without attributes and alias. If no name is defined for the composition, the name of the composition is the name of the target entity target and this name must be made available in the SELECT list.

Usage:

  • Fields from a composition target can't be used locally in path expressions. Fields from the composition target can't be used in the SELECT list, WHERE clause, or any other position of the view entity in which it is defined.
This also applies to CDS view extension. A field from a composition target can't be added to a CDS view entity via EXTEND VIEW ENTITY.
  • A composition can be propagated in data definitions other than the one in which it is defined. In this case, the composition uses its special semantics and is handled like a normal CDS association.
  • When a composition is used in another data definition, metadata extension, or view extension other than the one in which it is defined, then it can be used in a path expression. Parameter passing and defining attributes is also possible in this case.
  • Compositions can be used in annotation values (such as AnnotationRef or ElementRef) in the CDS entities that define them, since this does not lead to an SQL join.

Compositions and joins:

Notes

  • Cyclical dependencies should be avoided when using compositions to prevent problems occurring in mass activations of CDS entities.
  • Compositions can be given annotations in the element list element_list of the CDS entity in which they are defined.
  • Defining new compositions is not supported in views with set operators.

Example

The CDS view entity DEMO_SALES_CDS_SO_I_VE shown below returns information about sales order items. It defines three associations, one of them being a composition. The composition target (i.e. the child entity) is the CDS view entity DEMO_SALES_CDS_SO_I_SL_VE.

Explanation: Each sales order item can have one or more schedule lines, but schedule lines can exist only in connection with sales order items.

In the SELECT list, the composition _ScheduleLine is exposed, so it can be accessed from external CDS entities.






BAL_S_LOG - Application Log: Log header data   General Material Data  
This documentation is copyright by SAP AG.

Length: 10419 Date: 20240419 Time: 112123     sap01-206 ( 111 ms )