Ansicht
Dokumentation

ABENCDS_TO_PARENT_ASSOC_V2 - CDS TO PARENT ASSOC V2

ABENCDS_TO_PARENT_ASSOC_V2 - CDS TO PARENT ASSOC V2

Addresses (Business Address Services)   BAL_S_LOG - Application Log: Log header data  
This documentation is copyright by SAP AG.
SAP E-Book

- CDS View Entity, ASSOCIATION TO PARENT

... ASSOCIATION TO PARENT target $[AS _assoc$] ON $projection. cds_cond ...

Effect

A CDS to-parent association in ABAP CDS is a specialized CDS association. It is the counterpart of a CDS composition. A CDS composition is defined in the parent entity and points to the child entity, while a CDS to-parent association in defined in the child entity and points to the parent entity. Compositions and to-parent associations together define the CDS composition tree of a RAP business object in the context of the ABAP RESTful Application Programming Model.

A to-parent association is defined in a SELECT statement of a CDS view entity using the keyword ASSOCIATION TO PARENT. A to-parent association associates the current CDS entity, as association source, with the association target target specified in the definition of the association.

The child entity must always define a to-parent association first and only afterwards can a CDS composition be defined in the parent entity. The other way around results in a syntax error. The to-parent association cannot be deleted as long as the child entity is the target of the composition. The composition must be deleted first and then the to-parent association can be deleted.

Rules

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

  • Similarities

  • An ON condition must be defined. The rules for ON conditions of to-parent associations are listed below.

  • Differences
  • A default filter cannot be defined for a to-parent association. The syntax ... WITH DEFAULT FILTER ... is not allowed.

  • The cardinality cannot be defined explicitly for to-parent associations and is generated as [1..1].

The following applies to the association target target:

  • The association target of a to-parent association cannot be the CDS entity in which the to-parent association is defined. This means that to-parent associations cannot be self associations.
  • The target entity of a CDS composition and a to-parent association defined in the same data definition must be different entities.

General rules for child entities:

  • A child entity must define exactly one to-parent association to its parent entity.
  • A child entity that is the target of a CDS composition can itself be a parent entity and define further CDS compositions.
  • A root entity cannot define any to-parent associations.
  • The child entity in which the to-parent association is defined must have at least one key field.

Exposure:

  • The name of the to-parent association _assoc 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 to-parent association, the name of the to-parent association is the name of the target entity target and this name must be made available in the SELECT list.

Usage:

  • A to-parent association can be propagated in data definitions other than the one in which it is defined. In this case, the to-parent association uses its special semantics and is handled like a normal CDS association.
  • To-parent associations can be used in path expressions locally and also in other CDS entities in which they are propagated.
  • To-parent associations can be specified as values for AssociationRef associations. These to-parent associations are then handled as associations.

To-parent associations and joins:

Restrictions:

ON Condition

A to-parent association must define an ON condition. This ON condition is automatically used for the respective CDS composition in the parent entity.

The following rules apply to the operands and syntax of the ON condition:

  • Only key fields of the parent entity can be used in the ON condition.
  • The ON condition must use all key fields of the parent entity. Each one can be used only once in the ON condition.
  • Key fields of the parent entity can only be compared with fields of the child entity.
  • A field of the child entity can be used only once.
  • The fields of the association source must be prefixed by $projection.
  • The fields of the association target must be prefixed by the name of the CDS to-parent association (prefix _assoc. separated by a period).
  • Only the Boolean operator AND is allowed. Negations using NOT are not allowed.
  • lhs can be a field of the association source or association target.
  • rhs can be a field of the association source or association target.
  • Path expressions, expressions, built-in functions, and elementary operands are not allowed.
  • All fields that are used in the ON condition must be listed in the SELECT list.

Notes

  • A node that defines a to-parent association is not automatically a child entity of the business object. A node is only a child entity of the business object when it is the target of a composition.
  • To-parent associations can be given annotations in the element list of the CDS entity in which they are defined.

Example

The CDS view entity DEMO_SALES_CDS_SO_I_SL_VE shown below returns information about schedule lines of sales order items. It defines a to-parent association to the CDS view entity DEMO_SALES_CDS_SO_I_VE that contains information about sales orders.

In the SELECT list, the to-parent association _SalesOrderItem is exposed, so it can be accessed from external CDS entities.






ROGBILLS - Synchronize billing plans   SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up  
This documentation is copyright by SAP AG.

Length: 13662 Date: 20240419 Time: 112624     sap01-206 ( 130 ms )