Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing External Data →  ABAP Database Access →  ABAP SQL →  ABAP SQL - Operands and Expressions 

ABAP SQL - SQL path expressions sql_path

Other versions: 7.31 | 7.40 | 7.54

Syntax


... [source~]_assoc1[
sql_para][attributes] 
            [_assoc2[ sql_para][attributes]]
            [...] ...

Effect

Specifies an SQL path expression. ABAP SQL statements can contain path expressions in certain operand positions whose root element must be a CDS association or CTE association published as follows:

In a path expression, the names of associations _assoc1, _assoc2, ... are separated by backslashes (\). Associations specified after the root element must be published in the target data source of the directly prefixed association in the path expression. No CDS associations can occur that are defined in an abstract CDS entity or whose target data sources are an abstract CDS entity.

When a SELECT statement is compiled using path expressions, the joins represented by these expressions are implicitly added to the FROM clause of the statement. The resulting additional data sources are implicitly evaluated at the occurrences of the path expressions. This respects the join conditions of the associations and the other conditions of the CDS entities or common table expressions in question. Path expressions can be used:

  • In the specified columns of SELECT statements of queries.
    The path expression represents a left outer join (LEFT OUTER JOIN) by default.

When specifying columns and when publishing an association, an optional source unit can be specified before the path expression, separated by a column selector ~. The first association of this unit is published. This is either a CDS view, a CDS hierarchy, or a common table expression. However, when used as a data source, the path expression leads directly to the published unit anyway.

An association has the cardinality defined implicitly or explicitly in the CDS entity or common table expression by default. Syntax warnings or syntax errors occur when the cardinality does not match the way the path expression is used in the SELECT statement. If the association has the cardinality "to 1", the addition MANY TO ONE is added implicitly in the case of a LEFT OUTER JOIN on databases where this is supported. The consequences of this behavior should be noted. The following can be done after an association:

  • Actual parameters can be passed to input parameters of the data source of a CDS association by using sql_para.
  • The following attributes can be specified for the section of the path expression using attributes:
  • Cardinality of the association
  • Category of the join expression
  • Filter conditions

A path expression can be split across multiple lines of source code at the following places:

  • In front of a backslash (\), but not in the SELECT list
  • In blanks in parentheses in parameter passing
  • In blanks in parentheses in square brackets for attributes

Certain restrictions apply to the associations of path expressions in ABAP SQL.


Notes

  • When the associations of the path expressions are defined as joins, they are mapped to as few join expressions as possible. Associations with identical parameter passing and semantically identical attributes generally produce only one join expression.

  • If the specified columns of different clauses are checked for matches in a SELECT statement, any parameters specified and attributes are also checked. Here, the same host variables must be used in the same operand positions too.

Example

Simple path specified for the CDS association _spfli_scarr from the following CDS view:

@AbapCatalog.sqlViewName: 'DEMO_CDS_ASSOC'
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view demo_cds_association(
_spfli_scarr,
id,
carrier,
flight,
departure,
destination
)
as select from
spfli
association [1..1] to scarr as _spfli_scarr on
$projection.carrid = _spfli_scarr.carrid
{
_spfli_scarr,
key spfli.carrid,
key _spfli_scarr[inner].carrname,
key spfli.connid,
spfli.cityfrom,
spfli.cityto
}    

The program DEMO_CDS_ASSOCIATION uses the following SELECT statement with the simple path _spfli_scarr for the view and compares it with accesses to the data that work in the same way.

SELECT id, 
       \_spfli_scarr[ (1) INNER ]-carrname AS carrier, 
       flight, 
       departure, 
       destination 
       FROM demo_cds_association 
       INTO TABLE @DATA(result).

A SELECT statement that access the full SELECT list of the view and a SELECT statement that accesses a view with a join of the same type produce the same result.

Executable Examples

Continue

ABAP SQL - Path Expressions, attributes

ABAP SQL - Restrictions for Path Expressions

Path Expressions, Use in the SELECT List

Path Expressions, Use in the FROM Clause