SAP CDS TO PARENT ASSOC V1 Get Example source ABAP code based on a different SAP table
SAP Help
• ASSOCIATION TO PARENT ABAP_CDS_SELECT_V1
• AS ABAP_CDS_SELECT_ATP_V1
• ON ABAP_CDS_SELECT_ATP_V1
ABAP_CDS_DDL - DDIC-Based View, ASSOCIATION TO PARENT> ABAP_SYNTAX ... ASSOCIATION TO PARENT target $[AS _assoc$] ON $projection. cds_cond> ...> What does it do? 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. Both parent and child entity must define mutual associations. 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 DDIC-based view> 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 For the name AS _assoc>, the same rules apply as for normal CDS associations, see topic TITLE >. 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 can be another CDS view entity >, a ABAP_CDS_V1_VIEW >, an abstract entity >, or a custom entity>. 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 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: All use cases and details about join generation described in topic CDS DDL - DDIC-based View, Associations and Joins>> also apply to to-parent associations. Restrictions: To-parent associations cannot be defined in a CDS view extension>, neither with EXTEND VIEW> >, nor with EXTEND VIEW ENTITY>>. 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 comparison operator> => is allowed. No other relational operator > or comparison operator is allowed. 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. Latest 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. NON_V5_HINTS ABAP_HINT_END ABAP_EXAMPLE_VX5 The CDS view DEMO_SALES_CDS_SO_I_SL> shown below returns information about schedule lines of sales order items. It defines a to-parent association to the CDS view DEMO_SALES_CDS_SO_I > 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. DDLS DEMO_SALES_CDS_SO_I_SL ABAP_EXAMPLE_END