ABAP Keyword Documentation → ABAP Dictionary → ABAP CDS in ABAP Dictionary → ABAP CDS - Views → ABAP CDS - DDL Statements → ABAP CDS - DEFINE VIEW → ABAP CDS - SELECT → ABAP CDS - SELECT, association
ABAP CDS - path_expr
Other versions:
7.31 | 7.40 | 7.54
Syntax
... [viewEntity.]assoc1[parameters][attributes]
[.assoc2
[parameters][attributes] ... ][.element] ...
Effect
Defines a path expression in a SELECT statement of a CDS view in ABAP CDS. A path expression is a string of associations whose names are specified using assoc1, assoc2, ... If a CDS view is accessed using a path expression, the joins defined by the associations are evaluated from left to right and the path expression addresses the entire result of this evaluation or a single element appended using .element.
- If the path expression is closed using an element, this must be an element of the target data source of the final association in the path.
- If the path expression is closed using an association, this interpreted as follows depending on the position of the path expression:
- After FROM, the association is a data source data_source.
- In the SELECT list, the association defines an element of this list. This makes it accessible for other CDS views.
The name of the CDS view in which the first association is defined can be specified in front of this association. The associations used in a path expression can either be defined in the current CDS view or they can be elements of a data source of the current view.
- attributes can be used to specify attributes in pointy brackets after every association. These attributes define the following further properties of this section of the path expression:
- Declaration of monovalency
- Category of the join expression
- Specification of filter conditions
- If the data source entity of a specified association is a CDS view with a list of input parameters, parameters must be used after the name assoc to pass actual parameters to them.
Path expressions can be specified in the DDL of ABAP CDS as the data source data_source, as elements of SELECT lists, and as operands of WHERE conditions or HAVING conditions. Path expressions specified as operands of a condition must be closed using an element. As a non-aggregated element of a SELECT list with aggregate expressions and in a WHERE condition or HAVING condition, it can contain only filter conditions that are declared using the addition 1:.
Notes
- The most simple path expression is the name of a single association.
- DDL path expressions can also be used in conditions in the ABAP CDS DCL.
- The predefined annotation AbapCatalog.compiler.compareFilter can be used to specify whether the filter conditions are compared for the path expressions of a view. If the filter condition matches, the associated join expression is evaluated only once, which generally improves performance. Otherwise a separate join expression is created and evaluated for each filter condition. The results sets of both configurations can, however, differ.
Example
This example shows three CDS views, sales_order, business_partner, and invoice. The CDS view invoice uses its own association and associations from the other two views in path expressions:
- The association sales_order of the CDS view business_partner is specified as a data source after FROM. A filter condition guarantees that only certain orders can be used as data sources.
- The separate association invoice_header is used in a path expression as an operand in the WHERE condition.
- The association note_header of the CDS view sales_order is addressed using the alternative name bpa in business_partner and defined as an element of the SELECT list. This means this association can also be used in CDS views that use invoice as a data source.
define view sales_order as
select from snwd_so
association [0..1] to snwd_text_key as note_header
on snwd_so.note_guid = note_header.node_key
{ * } // Include all fields from snwd_text_key
define view business_partner as
select from snwd_bpa
association [0..*] to sales_order
on snwd_bpa.node_key = sales_order.buyer_guid
{ * }
define view invoice as
select from
/* Association "sales_order" with filter as data source */
business_partner.sales_order[
lifecycle_status <> 'C' and lifecycle_status <> 'X']
as bpa_so //alias for data source
/* Association only used in this view definition */
association [0..1] to snwd_so_inv_head as invoice_header
on bpa_so.node_key = invoice_header.so_guid
{ key bpa_so.node_key, //Field from ON-condition in invoice_header
bpa_so.so_id,
bpa_so.note_guid, //Field from ON-condition in note_header
bpa_so.lifecycle_status,
/* Association is not published, but its element */
invoice_header.dunning_level,
/* Association from data source is published here */
bpa_so.note_header }
/* Path expression in WHERE clause */
where invoice_header.dunning_level > '0';