Ansicht
Dokumentation

ABENCDS_ASSOCIATIONS_AND_JOINS - CDS ASSOCIATIONS AND JOINS

ABENCDS_ASSOCIATIONS_AND_JOINS - CDS ASSOCIATIONS AND JOINS

RFUMSV00 - Advance Return for Tax on Sales/Purchases   rdisp/max_wprun_time - Maximum work process run time  
This documentation is copyright by SAP AG.
SAP E-Book

This topic describes the different use cases of CDS associations. It explains in which use case a join is generated on the database and which join type is generated each time. Examples and screenshots of the SQL statement generated on the database are provided to further illustrate the transformation into joins.

When a CDS association is instantiated as join on the database, then the association source represents the left side and the association target represents the right side of the join. The ON condition of the association is added to the ON condition of the join.

There are the following basic use cases for CDS associations:

Using a Path Expression in the FROM Clause

Use case: the data source of a CDS view entity after FROM is specified as path expression.

Example:

SQL statement generated on the database:

IMAGE @@ABDOC_ASSOC_6.png@@590@@174@@

The SQL statement generated on the database shows that the path expression is transformed into an inner join on the database.

Exposing a CDS Association

Use case: an association is defined and exposed in the element list of a CDS view entity. In this way, it can be used in other CDS entities. However, the association is not part of the output and no data is selected from the association target.

Example:

SQL statement generated on the database:

IMAGE @@ABDOC_ASSOC_1.png@@452@@119@@

The SQL statement generated on the database shows that no join is generated and that the association is not mentioned in the statement that is passed to the database.

Adding a Field from the Association Target to the Element List

Use case: an association is defined and an element from the association target is included in the element list of the same CDS view entity. In this example, the association is used, but not exposed, and therefore it cannot be used in path expressions of other CDS entities.

Example:

SQL statement generated on the database:

IMAGE @@ABDOC_ASSOC_2.png@@489@@173@@

The SQL statement generated on the database shows that the path expression is transformed into a left outer join on the database.

Using a Path Expression in the WHERE Clause

Use case: an association is defined and used in the WHERE condition of the same CDS view entity. In this example, the association is used, but not exposed, and therefore it cannot be used in path expressions of other CDS entities.

Example:

SQL statement generated on the database:

IMAGE @@ABDOC_ASSOC_3.png@@567@@196@@

The SQL statement generated on the database shows that the path expression is transformed into a left outer join with the cardinality many to one.

Using an Exposed Association in an External View

Use case: A CDS view entity uses an association that was defined and published in another CDS entity. The association is used in a path expression to include a field from the association target in the element list of the CDS view entity.

Example:

SQL statement generated on the database:

IMAGE @@ABDOC_ASSOC_4.png@@772@@166@@

The SQL statement generated on the database shows that the path expression is transformed into a left outer join on the database. Note that this happens in the view that uses the association, and not in the view that defines the association.

Using an Exposed Association in

Use case: The program DEMO_CDS_SELECT_ASSOC uses an association that was defined and published in a CDS view entity in a path expression in .

Example:

REPORT demo_cds_select_assoc.

CLASS demo DEFINITION
  PUBLIC SECTION.
    CLASS-METHODS main.
ENDCLASS.

CLASS demo IMPLEMENTATION.
  METHOD main.
    SELECT carrid,
           carrname,
           /_spfli[ (*) ]-connid
           FROM demo_cds_assoc_exposition
           INTO TABLE @DATA(result).
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  demo=>main( ).

SQL statement generated on the database:

IMAGE @@ABDOC_ASSOC_5.png@@539@@179@@

The path expression is transformed into a left outer join on the database.






Fill RESBD Structure from EBP Component Structure   General Data in Customer Master  
This documentation is copyright by SAP AG.

Length: 6259 Date: 20240425 Time: 193301     sap01-206 ( 73 ms )