ABAP - Keyword Documentation →  ABAP - Dictionary →  ABAP CDS in ABAP Dictionary →  ABAP CDS - Data Definitions →  ABAP CDS - DDL for Data Definitions →  ABAP CDS - DEFINE VIEW →  ABAP CDS - SELECT →  ABAP CDS - SELECT, association → 

ABAP CDS - path_expr

Syntax

... [viewEntity.]_assoc1[ parameters][attributes]
               [._assoc2[ parameters][ attributes] ... ][.element] ...

Effect

Defines a path expression in a SELECT statement of a CDS view. A path expression is a string of associations separated by periods (.) whose names are specified using _assoc1, _assoc2, and so on.

Path expressions can be specified in the ABAP CDS DDL as data sources 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 of aggregate expressions and in a WHERE condition or HAVING condition, the result of the path expression must be monovalent. This means that the cardinality of all associations used is either "to 1" or the path expression can contain only filter conditions that are declared as monovalent using the addition 1:.

The following is evaluated when a CDS view is accessed using a path expression:

The path expression addresses the full result of this evaluation or a single element appended using .element.

In a WHERE clause or HAVING clause, the path expression must be closed using an element.

The name of the CDS view in which the first association is defined can be specified in front of this association. The first association in a path expression must either be defined in the current CDS view or published as an element in a data source of the current view. All further associations must be published in the target data source of the directly prefixed association in the path expression.

Notes

Example

The following CDS view contains the simple path expression _scarr[inner].carrname in the SELECT list, whereby the attribute INNER is specified that controls the type of join. The program DEMO_FROM_JOIN_TO_ASSOCIATION demonstrates that this view returns the same result as a directly programmed inner join in ABAP CDS or in Open SQL.

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:

@AbapCatalog.sqlViewName: 'SALES_ORDER_VW'
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

@AbapCatalog.sqlViewName: 'BPA_VW'
define view business_partner as
  select from snwd_bpa
         association [0..*] to sales_order
           on snwd_bpa.node_key = sales_order.buyer_guid
  { * }

@AbapCatalog.sqlViewName: 'SALESO_INV_VW'
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';

Executable Example

Path Expressions, Use in the SELECT List .



Continue
ABAP CDS - path_expr, attributes
Example ABAP CDS - Joins of Associations