SAP CDS EXPOSE ASSOC V1 ABEXA



Get Example source ABAP code based on a different SAP table
  



ABAP_CDS_DDL - DDIC-Based View, Exposing CDS Associations
This example demonstrates how CDS associations are exposed in the SELECT list of a CDS view.

ABAP_SOURCE_CODE
DEMO CL_DEMO_CDS_EXPOSE_ASSCTNS

ABAP_DESCRIPTION
The example demonstrates how CDS associations are accessed that are exposed in the SELECT list of CDS views. For each view, the data source is specified not directly, but as path expression, making use of an exposed association. As a comparison, the explicit join expression that produces the same result is shown.
The following CDS view exposes its CDS association _demo_join2, which associates its data source demo_join1 with the DDIC database table demo_join1. The field d used in the ON condition of the association source must also be an element of the SELECT list.
DDLS DEMO_CDS_EXPOSE_ASSOC_1 When the CDS association demo_cds_expose_assoc_1 _demo_join2 is accessed, the same inner join is created, that is explicitly used in the subsequent access. Both produce the same result.
The following CDS view matches the preceding view, but has an additional WHERE condition.
DDLS DEMO_CDS_EXPOSE_ASSOC_1A When the CDS association demo_cds_expose_assoc_1a _demo_join2 is accessed, the result set of the left side of the join is restricted by the WHERE condition in the association source of the path expression.
The following CDS view accesses the view demo_cds_expose_assoc_1 above. It does not have its own CDS association, but it does expose the CDS association of its data source demo_cds_expose_assoc_1._demo_join2. Here, the field demo_cds_expose_assoc_1.d of the association source used in the ON condition must again be part of the SELECT list.
DDLS DEMO_CDS_EXPOSE_ASSOC_2 When the CDS association demo_cds_expose_assoc_2 _demo_join2 is accessed, the same inner join is created as the subsequent explicit inner join and produces the same result. The view demo_cds_expose_assoc_2 is not subject to any further restrictions, which means the result is the same as when demo_cds_expose_assoc_1 _demo_join2 is accessed.
The following CDS view matches the preceding view, but has an additional WHERE condition.
DDLS DEMO_CDS_EXPOSE_ASSOC_2A When the CDS association demo_cds_expose_assoc_2a _demo_join2 is accessed, the result set of the left side of the join is restricted by the WHERE condition in the association source of the path expression. This is different from accessing demo_cds_expose_assoc_1a _demo_join2. The CDS association defined in demo_cds_expose_assoc_1a is exposed, but the association source is demo_cds_expose_assoc_2a with a different WHERE condition.
The following CDS view accesses the view demo_cds_expose_assoc_1a above. It does not have its own CDS association, but it does expose the CDS association of its data source demo_cds_expose_assoc_1a._demo_join2.
DDLS DEMO_CDS_EXPOSE_ASSOC_3 When the CDS association demo_cds_expose_assoc_3 _demo_join2 is accessed, the subsequent access creates an instance of the explicitly used inner join and produces its result. The view demo_cds_expose_assoc_3 is not subject to any further restrictions, which means the result is the same as when demo_cds_expose_assoc_1a _demo_join2 is accessed.
The following CDS view matches the preceding view, but has an additional WHERE condition.
DDLS DEMO_CDS_EXPOSE_ASSOC_3A When the CDS association demo_cds_expose_assoc_3a _demo_join2 is accessed, the result set of the left side of the join is restricted by the WHERE condition in the association source of the path expression. The disjoint WHERE condition in demo_cds_expose_assoc_1a means that no matching rows are found, however, and the result set of the left side of the join is empty.