SAP WITH ASSOCIATIONS USING ABAP Statements



Get Example source ABAP code based on a different SAP table
  


• REDIRECTED TO VIA WITH ASSOCIATIONS

WITH, ASSOCIATIONS, path

ABAP_SYNTAX
... sql_path $[AS alias$]
$[REDIRECTED TO +cte VIA target$] ...

ABAP Addition
... REDIRECTED TO +cte VIA target

What does it do?
Specifies an existing CDS association or CTE association using an SQL path expression sql_path in the addition WITH ASSOCIATIONS when a common table expression is defined in a WITH statement. The path expression exposes the association at its end. The exposing table expression is the association source of the exposed association and any join expressions that are created when the association is used in a path expression use the exposing table expression as their left side.
The root element of each path expression can be the following associations:
CDS associations
exposed in the SELECT list of a CDS view entity or a ABAP_CDS_V1_VIEW in cases where these views are used as a data source in the subquery of the common table expression.
exposed using WITH ASSOCIATIONS of preceding table expressions of the current WITH statement in cases where these table expressions are used as a data source in the subquery of the common table expression.
CTE associations defined and exposed using WITH ASSOCIATIONS of preceding table expressions of the current WITH statement in cases where these table expressions are used as a data source in the subquery of the common table expression.
If ~ is used to prefix the path expression with the name of the data source that exposes its first association, this name must be the name used in the table expression. Therefore, if AS is used to define an alias name, this name must be used instead of the original name in the path expression.
Parameter passing is not allowed in the final association of the specified path expressions and the type of the join must not be defined. All fields of the association source of a path expression that occur in the ON condition of the association must be elements of the SELECT list of the common table expression. In path expressions that contain only one association, the elements can be specified as single elements or by using * or dbtab~*. If a path expression contains more than one association, an element must be specified as a path expression closed by the field that has the same attributes as the path expression used for exposing.
AS can be used to specify an alias name alias for the exposed association, under which it can be addressed in the subsequent queries of the current WITH statement. The alias name can contain letters, digits, the minus sign (-), and the underscore (_ ) in any order.

ABAP_EXAMPLE_VX5
The following WITH statement is a syntax example only and does not have a function. Its main role is to show different ways of specifying path expressions and operands.
ABEXA 00772
ABAP_EXAMPLE_END

ABAP_EXAMPLE_ABEXA
Exposing Associations
ABAP_EXAMPLE_END

ABAP Addition

What does it do?
The addition REDIRECTED TO replaces the association target of the association exposed using WITH ASSOCIATIONS with the common table expression specified as +cte.
The following can be specified for +cte:
A common table expression defined in front of the current common table expression in the current WITH statement.
The current common table expression +cte must specify the association target as a data source of the exposed association in the FROM clause of the subquery.
VIA must be followed by the association target of the exposed association under the name it uses in the FROM clause of +cte :
The association target must be specified after VIA even if it is used only once. If AS is used to define an alias name, this name must be specified.
If the association target is used more than once as a data source of join expressions, one of these occurrences must be specified after VIA. The occurrence can be specified using the alias name or, if necessary, using its original name. All columns that occur in the ON condition of the exposed association must be listed as columns of the data source specified after VIA in the SELECT list of the subquery of +cte . If the association target occurs more than once in the FROM clause of +cte, the addition VIA defines that these columns of the result set, which represent the right side of the join expression created when the exposed association is used in a subsequent path expression, are used in the ON condition of the expression.
If an attribute is specified for the association target when the exposed association is used in a subsequent path expression, this attribute affects the target +cte of the redirect. An attribute specified after WITH ASSOCIATIONS when the association is exposed, however, is applied to the original association target of the exposed association.

ABAP_EXAMPLE_VX5
The common table expression +cte2 of the following WITH statement uses the path expression demo_cds_expose_assoc~ _spfli to expose the CDS association _spfli that is itself exposed in the CDS view demo_cds_expose_assoc. The common table expression +cte2 hence replaces this view as the association source of the CDS association. This is meaningless in this example, however, since the subquery of the common table expression reads all data from the data source. The common table expression +cte1 uses REDIRECTED TO +cte1~demo_cds_assoc_spfli to replace the association target demo_cds_assoc_spfli of the exposed path expression. demo_cds_assoc_spfli is the only data source of the common table expression +cte1. In the main query of the WITH statement, the path expression +cte2 _spfli is used to access the association target +cte1 of the exposed CDS association, which is restricted by the WHERE condition.
ABEXA 00773
DDL Source Code of DEMO_CDS_EXPOSE_ASSOC:
DDLS DEMO_CDS_EXPOSE_ASSOC
DDL Source Code of DEMO_CDS_ASSOC_SPFLI:
DDLS DEMO_CDS_ASSOC_SPFLI
ABAP_EXAMPLE_END

ABAP_EXAMPLES_ABEXA
Exposing Associations with a Redirect
Exposing Associations with a Recursive Redirect
ABAP_EXAMPLE_END

Return to menu