SAP CDS PATH EXPRESSION V2
Get Example source ABAP code based on a different SAP table
• . ABAP_CDS_PATH_EXPR
ABAP_CDS_DDL - CDS View Entity, path_expr> ABAP_SYNTAX ... $[source.$]_assoc1$[parameters >$]$[attributes>$]
$[._assoc2$[parameters> $]$[attributes>$] ... $] ... >
What does it do?
Specifies an SQL path expression > that can be used in a SELECT> statement of a CDS view entity>. A path expression of the CDS DDL> is a sequence of CDS associations> separated by periods (.>) whose names are specified using _assoc1>, _assoc2>, and so on. If the first CDS association is exposed in another CDS entity, the name of this CDS entity can be specified as source.> in front of the path expression.
A path expression may consist of a mixture of compositions, to-parent associations, and regular CDS associations.
The first CDS association of a path expression must be either defined in the current CDS view entity, or exposed as an element of the SELECT > list or of the element list> in a CDS view entity or CDS hierarchy that is a data source of the current view.
All further CDS associations must be exposed in the association target> of the directly prefixed CDS association in the path expression. It is not possible to use a CDS association in a path expression that is defined in a CDS abstract entity> or in a CDS custom entity>.
attributes>> can be used to specify attributes in angle brackets after every CDS association. These attributes define the following further properties of this section of the path expression:
Cardinality>
Join type> implemented when used
Filter conditions>
If the association target of a specified CDS association is a CDS entity with input parameters>, then actual parameters must be passed to them, using parameters>> after the name _assoc>. Only in one use case, it is not possible to specify values for the actual parameters, namely when a CDS association is exposed in a path expression as an element> of a SELECT>> list.
Use of Path Expressions>
Path expressions can be used as follows in the CDS DDL in ABAP CDS:
They can expose> their final CDS associations as elements> of SELECT> lists> for use in other CDS entities or in AB_SQL .
Path expressions with CDS associations whose association target> is not a CDS abstract entity> or a CDS custom entity> can be used as follows:
To specify the association target> of the final CDS association as the data source data_source>> after FROM>>. The path expression represents an inner join> by default.
To specify an element .element> of the association target> of the last CDS association as an element> of a SELECT> list>. The path expression represents a left outer join> by default.
To specify an element .element> of the association target> of the last CDS association as an operand of WHERE> >, HAVING>>, or WHEN>> conditions. The path expression represents a left outer join > by default.
To specify an element .element> of the association target> of the last CDS association after GROUP BY>. The path expression represents a left outer join> by default.
To specify an element .element> of the association target> of the last CDS association as an operand of an aggregate expression>, a built-in function>, a case expression>, or a cast expression>. The path expression represents a left outer join> by default. In the case of self associations in which the association target> is the same as the association source>, these usages are not possible in the CDS entity where they are defined.
For a non-aggregated element of a SELECT> list that contains aggregate expressions>, as well as in a WHERE> and HAVING> condition, the result of the path expression must be unique. This means that the cardinality> of all CDS associations used must be either to-one or the path expression can contain only filter conditions> that are declared as unique using the addition 1:>.
When a CDS entity with a path expression is accessed, the following is evaluated:
The joins defined by the CDS associations, from left to right.
All other conditions of the CDS entities involved.
The path expression addresses the full result of this evaluation or a single element .element>.
Latest notes:
The most simple path expression is the name of a single CDS association.
For joins of CDS associations used in path expressions, note that their left side is always the CDS entity that exposes the CDS association. This applies particularly to CDS associations that are exposed in data sources of CDS entities and passed on.
CDS DDL path expressions can also be used in the ABAP CDS DCL> of ABAP CDS to specify conditions>.
A CDS association whose association target> does not expose a CDS association cannot be followed by any further associations in a path expression. More specifically, for CDS associations whose association targets are DDIC database tables or DDIC views, no further CDS associations can be specified in a path expression .
When the CDS associations of the path expressions of a view are implemented as joins, they are automatically mapped to as few join expressions as possible. CDS associations with semantically identical filter conditions are automatically summarized into one single join expression.
Path expressions with CDS associations whose association target> is a non-SQL CDS entity> cannot be used anywhere where they could produce instances of join expressions.
NON_V5_HINTS
ABAP_HINT_END
ABAP_EXAMPLE_VX5
The following CDS view entity contains the simple path expression _scarr[inner].carrname> in its SELECT> list. The attribute INNER>> controls the join type>. The class CL_DEMO_FROM_JOIN_TO_ASSOC_VE>> demonstrates that this view returns the same result as a directly programmed inner join in ABAP CDS or in AB_SQL .
DDLS DEMO_CDS_JOIN2_VE
ABAP_EXAMPLE_END
ABAP_EXAMPLE_VX5
The CDS view entity DEMO_SALES_CDS_PATH_EXPR> uses its own association and associations from other CDS entities in path expressions:
The CDS association _SalesOrder> of the DDIC-based view DEMO_SALES_CDS_SO_I> is specified as a data source after FROM >. A filter condition guarantees that only certain orders can be used as data sources.
The CDS association invoice_header>, which is defined by the view DEMO_SALES_CDS_PATH_EXPR> itself, is used in a path expression as an operand in the WHERE> condition.
The CDS association _Buyer> of the CDS view DEMO_SALES_CDS_SO > is exposed via a path expression in the SELECT> list. This means that this CDS association can also be used in CDS view entities that use DEMO_SALES_CDS_PATH_EXPR> as a data source.
DDLS DEMO_SALES_CDS_PATH_EXPR
ABAP_EXAMPLE_END
ABAP_EXAMPLE_ABEXA
Path Expressions, Use in the SELECT> List>
ABAP_EXAMPLE_END