SAP WITH ASSOCS REDIRECT ABEXA



Get Example source ABAP code based on a different SAP table
  



WITH, Exposing Associations with a Redirect
This example demonstrates the addition REDIRECTED of WITH ASSOCIATIONS for common table expressions.

ABAP_SOURCE_CODE
DEMO CL_DEMO_WITH_ASSOCS_REDIR

ABAP_DESCRIPTION
The common table expression +cte2 accesses a CDS view entity using the following source code:
DDLS DEMO_CDS_EXPOSE_ASSOC_1
This example demonstrates different redirects of the association target of the CDS association demo_cds_expose_assoc_1~ _demo_join2 exposed by +cte2 to a preceding common table expression +cte1:
The first WITH statement shows a simple example in which the association target demo_join2 of the CDS association _demo_join2 exposed by +cte2 occurs once under its name in +cte1 as a data source. Only demo_join2 can be specified after VIA. When the path expression +cte2 _demo_join2 is accessed, an inner join is created between the result sets of +cte2 and +cte1, whose ON condition compares the columns of the result sets defined by the CDS association.
The next WITH statements show examples in which the association target demo_join2 of the CDS association _demo_join2 exposed by +cte2 occurs twice as a data source in +cte1 under different names, src1 and src2.
src1 is specified after VIA in the redirect of the first WITH statement. The ON condition of the join instance created when the path expression is accessed uses the column of the result set determined bysrc1.
src2 is specified after VIA in the redirect of the second WITH statement. The ON condition of the join instance created when the path expression is accessed uses the column of the result set determined bysrc2.
The next two WITH statements repeat the preceding statements with a different WHERE condition in +cte1, which then produces different results.
The results of all reads are different from each other. The following reads demonstrate which join instances are created:
First, the same WITH statements are executed as above, but the CDS association is not exposed. Instead, the inner join between the two common table expressions is shown explicitly. More specifically, the difference between the ON conditions +cte2~d = +cte1~src1_d and cte2~d = +cte1~src2_d should be noted, which demonstrates the effect of the data sources specified using VIA.
The subqueries of the WITH statements are then executed as separate SELECT statements to store their results in internal tables for display purposes. Joins are also realized from internal tables using the value operator VALUE.
The example ensures that the results of associated reads also match each other.