SAP CDS PROJ VIEW REDEFINED ASSOC



Get Example source ABAP code based on a different SAP table
  


• REDEFINE ASSOCIATION ABAP_CDS_PROJ_VIEW

ABAP_CDS_DDL - REDEFINE ASSOCIATION, Transactional Query

ABAP_SYNTAX
... REDEFINE ASSOCIATION $[source.$]_ProjAssoc $[ filter$] $[AS _RedefinedName $] redirection ...

What does it do?
A CDS association from the projected entity can be redefined in the header part, that means in front of the projection list , of a CDS projection view. In this way, it is possible to modify an association from the underlying view. The modified association can be used locally and it can be exposed in the projection list for usage in, for example, CDS view entity extensions.
The syntax consists of the following elements:
_ProjAssoc: the association from the projected entity which should be redefined must be identified by its original name. The association source source can optionally be specified as prefix.
filter: A filter, consisting of a filter condition and, optionally, a cardinality, can be specified. See topic CDS Projection View, filter for details. The following rules apply in addition to the rules described in topic CDS Projection View, filter:
If the numeric syntax variant is used, the min cardinality can be 0 or 1. The max cardinality can be 1 or *. The min and max cardinality of redefined to-parent redirects must not be changed.
AS alias: A new alias name AS alias can be assigned.
redirection: This addition is mandatory for redefined associations. As a prerequisite, the original association target must also have a CDS projection view. Redirection using the keyword REDIRECTED TO $[...$] means to direct an association to a new association target, which is also a CDS projection view, in this way moving the complete data model to the projection layer . See topic CDS Projection View, redirection for further details.
Exposure in the projection list:
The redefined association can be exposed, but exposure is not mandatory, as it can also be done in CDS view entity extensions later on.
Even if an association has been redefined, it is still possible to expose the original association by using the source as prefix. Example:
Expose redefined association: _assoc.
Expose original association: source._assoc
The redefined association can be used in path expressions to expose fields from the association target in the projection list. If a filter condition was added to the redefined association in the header, this is automatically applied to all fields exposed via a path expression.
A new alias name can be assigned when exposing a redefined association, even if an alias has already been defined in the context of the redefinition.
A new filter condition with a new cardinality can be specified when exposing a redefined association, even if a filter condition with a cardinality has already been defined in the context of the redefinition. In this case, a new alias name is mandatory.
All elements included in the ON clause of an exposed redefined association must also be included in the projection list.
Limitations
It is not possible to redefine locally defined associations.
_ProjAssoc cannot be specified as path expression.



Latest notes:

As alternative to the redefinition described in this topic, a filter condition and redirection can also be specified in the projection list when exposing the association. See topic CDS Projection View, expose_assoc for details.
The syntax described in this topic can also be used in a CDS view entity extension using EXTEND VIEW ENTITY .
NON_V5_HINTS
ABAP_HINT_END
VX_EXA_ONLY

ABAP_EXAMPLE_VX
The following two CDS projection views define a CDS composition relationship to each other. Both of them redefine their associations and redirect the association target to the projection layer, while maintaining the specialization. The CDS view entity extension DEMO_CDS_PV_EXTEND redefines an association to a foreign entity which is not part of the same CDS composition tree .
Parent CDS projection view
DDLS DEMO_CDS_PV_PARENT
Child CDS projection view
DDLS DEMO_CDS_PV_CHILD
CDS view entity extension extending the parent view
DDLS DEMO_CDS_PV_EXTEND
ABAP_EXAMPLE_END