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, select_list → ABAP CDS - SELECT, element → ABAP CDS - SELECT, association
ABAP CDS - Publishing CDS Associations
This example demonstrates how CDS associations are published in the SELECT list of a CDS view.
Other versions:
7.31 | 7.40 | 7.54
Source Code
DATA(out) = cl_demo_output=>new( ).
"Using published association in FROM clause
SELECT *
FROM demo_cds_publish_assoc_1\_demo_join2
INTO TABLE @DATA(result1).
"Explicit join
SELECT demo_join2~*
FROM demo_cds_publish_assoc_1
INNER JOIN demo_join2
ON demo_cds_publish_assoc_1~d = demo_join2~d
INTO TABLE @DATA(result1e).
ASSERT result1 = result1e.
out->write( result1 ).
"Using published association in FROM clause
SELECT *
FROM demo_cds_publish_assoc_1a\_demo_join2
INTO TABLE @DATA(result1a).
"Explicit join
SELECT demo_join2~*
FROM demo_cds_publish_assoc_1a
INNER JOIN demo_join2
ON demo_cds_publish_assoc_1a~d = demo_join2~d
INTO TABLE @DATA(result1ae).
ASSERT result1a = result1ae.
out->write( result1a ).
"Using propagated association in FROM clause
SELECT *
FROM demo_cds_publish_assoc_2\_demo_join2
INTO TABLE @DATA(result2).
"Explicit join
SELECT demo_join2~*
FROM demo_cds_publish_assoc_2
INNER JOIN demo_join2
ON demo_cds_publish_assoc_2~d = demo_join2~d
INTO TABLE @DATA(result2e).
ASSERT result2 = result2e.
out->write( result2 ).
"Using propagated association in FROM clause
SELECT *
FROM demo_cds_publish_assoc_2a\_demo_join2
INTO TABLE @DATA(result2a).
"Explicit join
SELECT demo_join2~*
FROM demo_cds_publish_assoc_2a
INNER JOIN demo_join2
ON demo_cds_publish_assoc_2a~d = demo_join2~d
INTO TABLE @DATA(result2ae).
ASSERT result2a = result2ae.
out->write( result2a ).
"Using propagated association in FROM clause
SELECT *
FROM demo_cds_publish_assoc_3\_demo_join2
INTO TABLE @DATA(result3).
"Explicit join
SELECT demo_join2~*
FROM demo_cds_publish_assoc_3
INNER JOIN demo_join2
ON demo_cds_publish_assoc_3~d = demo_join2~d
INTO TABLE @DATA(result3e).
ASSERT result3 = result3e.
out->write( result3 ).
"Using propagated association in FROM clause
SELECT *
FROM demo_cds_publish_assoc_3a\_demo_join2
INTO TABLE @DATA(result3a).
"Explicit join
SELECT demo_join2~*
FROM demo_cds_publish_assoc_3a
INNER JOIN demo_join2
ON demo_cds_publish_assoc_3a~d = demo_join2~d
INTO TABLE @DATA(result3ae).
ASSERT result3a = result3ae.
out->write( result3a ).
out->display( ).
Description
It also demonstrates how CDS
associations are accessed that are published in their SELECT list
using CDS views. For each view, a use of the published CDS association as a data source of a SELECT
statement in a
path expression is shown. As a comparison, the explicit join expression that produces the same result is shown.
- The following CDS view publishes its CDS association _demo_join2, which associates its data source demo_join1 with the database table demo_join1. The field d used in the ON condition of the source data source must also be an element of the SELECT list.
define view demo_cds_publish_assoc_1
as select from
demo_join1
association to demo_join2 as _demo_join2 on
_demo_join2.d = demo_join1.d
{
_demo_join2,
demo_join1.d
}
demo_cds_publish_assoc_1\_demo_join2
is accessed, the subsequent access creates an instance of the explicitly used inner join and produces its result.
- The following CDS view matches the preceding view, but has an additional WHERE condition.
define view demo_cds_publish_assoc_1a
as select from
demo_join1
association to demo_join2 as _demo_join2 on
_demo_join2.d = demo_join1.d
{
_demo_join2,
demo_join1.d
}
where
d = 'ww'
demo_cds_publish_assoc_1a\_demo_join2
is accessed,
the results set of the left side of the join is restricted by the WHERE condition in the source data source of the path expression.
- The following CDS view accesses the view demo_cds_publish_assoc_1 above. It does not have its own CDS association, but it does publish the CDS association of its data source demo_cds_publish_assoc_1._demo_join2. Here, the field demo_cds_publish_assoc_1.d of the source data source used in the ON condition must again be part of the SELECT list.
define view demo_cds_publish_assoc_2
as select from
demo_cds_publish_assoc_1
{
demo_cds_publish_assoc_1._demo_join2,
demo_cds_publish_assoc_1.d
}
demo_cds_publish_assoc_2\_demo_join2
is accessed,
the subsequent access creates an instance of the explicitly used inner join and produces its result.
The view demo_cds_publish_assoc_2 is not subject to any further restrictions,
which means the result is the same as when demo_cds_publish_assoc_1\_demo_join2
is accessed.
- The following CDS view matches the preceding view, but has an additional WHERE condition.
define view demo_cds_publish_assoc_2a
as select from
demo_cds_publish_assoc_1
{
demo_cds_publish_assoc_1._demo_join2,
demo_cds_publish_assoc_1.d
}
where
d = 'xx'
demo_cds_publish_assoc_2a\_demo_join2
is accessed,
the results set of the left side of the join is restricted by the WHERE
condition in the source data source of the path expression. This is different from accessing demo_cds_publish_assoc_1a\_demo_join2
.
The CDS association defined in demo_cds_publish_assoc_1a is published,
but the source data source is demo_cds_publish_assoc_2a with a different WHERE condition.
- The following CDS view accesses the view demo_cds_publish_assoc_1a above. It does not have its own CDS association, but it does publish the CDS association of its data source demo_cds_publish_assoc_1a._demo_join2.
define view demo_cds_publish_assoc_3
as select from
demo_cds_publish_assoc_1a
{
demo_cds_publish_assoc_1a._demo_join2,
demo_cds_publish_assoc_1a.d
}
demo_cds_publish_assoc_3\_demo_join2
is accessed,
the subsequent access creates an instance of the explicitly used inner join and produces its result.
The view demo_cds_publish_assoc_3 is not subject to any further restrictions,
which means the result is the same as when demo_cds_publish_assoc_1a\_demo_join2
is accessed.
- The following CDS view matches the preceding view, but has an additional WHERE condition.
define view demo_cds_publish_assoc_3A
as select from
demo_cds_publish_assoc_1a
{
demo_cds_publish_assoc_1a._demo_join2,
demo_cds_publish_assoc_1a.d
}
where
d = 'xx'
demo_cds_publish_assoc_3a\_demo_join2
is accessed,
the results set of the left side of the join is restricted by the WHERE
condition in the source data source of the path expression. The disjoint WHERE
condition in demo_cds_publish_assoc_1a means that no matching rows are found, however, and the results set of the left side of the join is empty.