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
ABAP CDS - path_expr, attributes
Other versions:
7.31 | 7.40 | 7.54
Syntax
... [ [1|*:] [INNER|{LEFT OUTER} [WHERE]] [
cond_expr] ] ...
Extras
1. ... 1|*:
2. ... INNER|{LEFT OUTER} [WHERE]
3. ... cond_expr
Effect
For every CDS association _assoc of a path expression of a CDS view, attributes for this part of the path expression can be defined in square brackets [ ]. The following can be done using these attributes:
- The polyvalence of the section can be declared.
- The type of the join expression can be specified.
- A filter condition cond_expr can be specified.
Addition 1
... 1|*:
Effect
Declaration of the polyvalence of the current CDS association:
- If the attribute 1: is specified, the current CDS association is declared as not polyvalent.
- If the attribute *: is specified, the current CDS association is declared as polyvalent.
The addition 1: makes it possible to use filter conditions in path expressions, which are used in WHERE clauses or HAVING clauses. In a clause like this, it overwrites the cardinality of the CDS association. (The variant of the path expression can, however, be affected differently on certain database systems.)
The addition 1: or *: cannot be specified as the only addition in square brackets.
Note
The addition 1: prevents a syntax error, if a path specified with filter conditions or with a quantity value cardinality is used in a WHERE clause or HAVING clause. It is not possible at runtime, however, to check whether the required uniqueness is achieved by the condition.
Addition 2
... INNER|{LEFT OUTER} [WHERE]
Effect
Defines the type of join expression where the current CDS association is implemented:
- INNER is an inner join
- LEFT OUTER is a left outer join
If the type of join expression is not specified explicitly, the type depends on the place where the path expression is used:
- After FROM, it is an inner join (INNER JOIN)
- In all other locations, it is a left outer join (LEFT OUTER JOIN)
If the type of join expression is defined before a filter condition cond_expr, the addition must be specified before the addition WHERE. If this is not the case, WHERE cannot be specified.
Note
In the DDL Source Text Editor of the ADT, you can view the configuration of the join in the display of the generated SQL DDL statement.
Executable Example
Addition 3
... cond_expr
Effect
Filter condition for the current CDS association. A filter condition is a condition cond_exp implemented as an expanded condition for the join when resolving the CDS association with the join in question. Special rules apply when specifying the condition.
If no filter condition is specified in the path expression, any default filter condition specified for the CDS association is used.
Note
In most cases, a filter condition modifies the join expression defined for a CDS association of a path expression on the database. This means that a separate join expression is defined for each CDS association with a filter condition by default. This is not necessary, however, if a CDS association is used more than once and the same filter condition is specified. This is why the ABAP annotation AbapCatalog.compiler.compareFilter can be used to configure whether the filter conditions of a multiple CDS association are compared semantically for the path expressions defined as joins when a view is activated . If the filter condition matches, the associated join expression is created only once, which generally improves performance. In most cases, it is best to use the annotation and propose it when creating a CDS view in the ADT. The results sets of the two configurations can, however, differ.
Example
The following three views contain path expressions with filter conditions in their SELECT list that can be defined in join expressions when activated.
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view demo_cds_assoc_filter1
as select from
demo_join1
association to Demo_Cds_Assoc_Join2 as _demo_join2 on
_demo_join2.d = demo_join1.d
{
_demo_join2[
inner where d = '1' ].d as d_2,
_demo_join2[
inner where d = '1' ].e as e_2,
_demo_join2[
inner where d = '1' ]._demo_join3[
inner where i = '2' ].i as i_3,
_demo_join2[
inner where d = '1' ]._demo_join3[
inner where i = '2' ].j as j_3
}
@AbapCatalog.compiler.compareFilter: false
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view demo_cds_assoc_filter2
as select from
demo_join1
association to Demo_Cds_Assoc_Join2 as _demo_join2 on
_demo_join2.d = demo_join1.d
{
_demo_join2[
inner where d = '1' ].d as d_2,
_demo_join2[
inner where d = '1' ].e as e_2,
_demo_join2[
inner where d = '1' ]._demo_join3[
inner where i = '2' ].i as i_3,
_demo_join2[
inner where d = '1' ]._demo_join3[
inner where i = '2' ].j as j_3
}
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view demo_cds_assoc_filter3
as select from
demo_join1
association to Demo_Cds_Assoc_Join2 as _demo_join2 on
_demo_join2.d = demo_join1.d
{
_demo_join2[
inner where d = '1' ].d as d_2,
_demo_join2[
inner where d = '2' ].e as e_2,
_demo_join2[
inner where d = '3' ]._demo_join3[
inner where i = '5' ].i as i_3,
_demo_join2[
inner where d = '4' ]._demo_join3[
inner where i = '6' ].j as j_3
}
In the first view, the annotation AbapCatalog.compiler.compareFilter has the recommended value true. The conditions are detected as identical and the variants of the path expressions on a SAP HANA database looks something like this:
"=A0"."D" AS "D_2",
"=A0"."E" AS "E_2",
"=A1"."I" AS "I_3",
"=A1"."J" AS "J_3"
FROM (
"DEMO_JOIN1" "DEMO_JOIN1" INNER JOIN "DEMO_CDS_ASJO2" "=A0" ON (
"=A0"."D" = "DEMO_JOIN1"."D" AND
"=A0"."D" = N'1'
)
) INNER JOIN "DEMO_JOIN3" "=A1" ON (
"=A1"."L" = "=A0"."D" AND
"=A1"."I" = N'2'
)
In the second view, AbapCatalog.compiler.compareFilter has the value false and a join expression is defined for each CDS association of the path expressions regardless of the identical conditions. This means that this variant looks like the variant of the third views (in which all conditions are different):
"=A0"."D" AS "D_2",
"=A1"."E" AS "E_2",
"=A3"."I" AS "I_3",
"=A5"."J" AS "J_3"
FROM (
(
(
(
(
"DEMO_JOIN1" "DEMO_JOIN1" INNER JOIN "DEMO_CDS_ASJO2" "=A0" ON (
"=A0"."D" = "DEMO_JOIN1"."D" AND
"=A0"."D" = N'1'
)
) INNER JOIN "DEMO_CDS_ASJO2" "=A1" ON (
"=A1"."D" = "DEMO_JOIN1"."D" AND
"=A1"."D" = N'1'
)
) INNER JOIN "DEMO_CDS_ASJO2" "=A2" ON (
"=A2"."D" = "DEMO_JOIN1"."D" AND
"=A2"."D" = N'1'
)
) INNER JOIN "DEMO_JOIN3" "=A3" ON (
"=A3"."L" = "=A2"."D" AND
"=A3"."I" = N'2'
)
) INNER JOIN "DEMO_CDS_ASJO2" "=A4" ON (
"=A4"."D" = "DEMO_JOIN1"."D" AND
"=A4"."D" = N'1'
)
) INNER JOIN "DEMO_JOIN3" "=A5" ON (
"=A5"."L" = "=A4"."D" AND
"=A5"."I" = N'2'
)
CREATE VIEW "DEMOCDSASSFI3" AS SELECT
"=A0"."D" AS "D_2",
"=A1"."E" AS "E_2",
"=A3"."I" AS "I_3",
"=A5"."J" AS "J_3"
FROM (
(
(
(
(
"DEMO_JOIN1" "DEMO_JOIN1" INNER JOIN "DEMO_CDS_ASJO2" "=A0" ON (
"=A0"."D" = "DEMO_JOIN1"."D" AND
"=A0"."D" = N'1'
)
) INNER JOIN "DEMO_CDS_ASJO2" "=A1" ON (
"=A1"."D" = "DEMO_JOIN1"."D" AND
"=A1"."D" = N'2'
)
) INNER JOIN "DEMO_CDS_ASJO2" "=A2" ON (
"=A2"."D" = "DEMO_JOIN1"."D" AND
"=A2"."D" = N'3'
)
) INNER JOIN "DEMO_JOIN3" "=A3" ON (
"=A3"."L" = "=A2"."D" AND
"=A3"."I" = N'5'
)
) INNER JOIN "DEMO_CDS_ASJO2" "=A4" ON (
"=A4"."D" = "DEMO_JOIN1"."D" AND
"=A4"."D" = N'4'
)
) INNER JOIN "DEMO_JOIN3" "=A5" ON (
"=A5"."L" = "=A4"."D" AND
"=A5"."I" = N'6'
)