SAP CDS COMPOSITION V1 Get Example source ABAP code based on a different SAP table
SAP Help
• COMPOSITION ABAP_CDS_SELECT_V1
• OF ABAP_CDS_SELECT_COMPV1
• AS ABAP_CDS_SELECT_COMPV1
ABAP_CDS_DDL - DDIC-Based View, COMPOSITION> ABAP_SYNTAX ... COMPOSITION $[ [min..max] $] OF target $[AS _compos$] ...> What does it do? A CDS composition> in ABAP CDS> is a specialized CDS association> that defines the current ABAP_CDS_V1_VIEW > as parent entity> of the composition target>. The composition target is the child entity>. Both parent and child entity must define mutual associations. 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. ABAP_PREREQUISITE 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. ABAP_PREREQ_END Rules CDS compositions are defined similarly to CDS associations. Here are the similarities and differences: Similarities For the cardinality> $[ [min..max] $] > and the name of the composition AS _compos>, the same rules apply as for a normal> CDS association, see topic TITLE >. 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>: The composition target can be a CDS view entity >, a ABAP_CDS_V1_VIEW >, an abstract entity >, or a custom entity>. 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> It must be a CDS entity>. If target> is a non-SQL CDS entity >, the way the composition can be used is restricted. 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: ABAP_CAUTION Fields from a composition target cannot> be used locally in path expressions. Fields from the composition target cannot 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 cannot be added to a CDS view entity via EXTEND VIEW >>. 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: The use cases and generation of joins described in topic CDS DDL - CDS View Entity, Associations and Joins>> also apply to CDS compositions, with the exception of use cases 3 and 4. Latest 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 UNION>> views. NON_V5_HINTS ABAP_HINT_END ABAP_EXAMPLE_VX5 The CDS view DEMO_SALES_CDS_SO_I> 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 DEMO_SALES_CDS_SO_I_SL>. 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. DDLS DEMO_SALES_CDS_SO_I ABAP_EXAMPLE_END