SAP CDS PROJ VIEW ASSOCIATION



Get Example source ABAP code based on a different SAP table
  


• ASSOCIATION ABAP_CDS_PROJ_VIEW
• [ ] ABAP_CDS_PROJ_VIEW
• ON ABAP_CDS_PROJ_VIEW
• TO ABAP_CDS_PROJ_VIEW
• WITH DEFAULT FILTER ABAP_CDS_PROJ_VIEW

ABAP_CDS_DDL - ASSOCIATION, Transactional Query

ABAP_SYNTAX
... ASSOCIATION $[cardinality$] TO target $[AS _assoc$] ON cds_cond
$[ WITH DEFAULT FILTER cds_cond $] ...

What does it do?
Defines a CDS association with the name _assoc in a CDS projection view. Possible association targets and rules are the same as for associations in CDS view entities, but there are further restrictions. The main difference is that the newly defined associations can only be exposed, but they cannot be used in path expressions to include elements from the association target . The purpose of defining new associations is to model new relationships which can be interpreted by consumer frameworks, such as the RAP query engine. However, no additional joins should be generated on CDS level by denormalizing fields from new association targets into the CDS projection view. Only simple associations can be defined in a CDS projection view. Specialized associations of type composition or to-parent are not supported.
All elements included in the ON clause of an exposed CDS association must also be included in the projection list of the CDS projection view.
Syntax rules
New associations in CDS projection views are defined in exactly the same way as associations in CDS view entities. The same rules apply to the cardinality specification, AS _assoc , WITH DEFAULT FILTER , and the ON condition. See topic CDS DDL - CDS View Entity, ASSOCIATION .
Possible association targets:
Same as for CDS view entities, see topic CDS View Entity, ASSOCIATION or Data Source Matrix.
Exposure in the projection list
The newly defined association can be exposed, but exposure is not mandatory, as it can also be done in CDS view entity extensions later on.
An alias name alias can be assigned to the exposed association.
It is possible to enhance a locally defined association with an additional filter when exposing it in the projection list. Two kinds of attributes can be added in square brackets as filter: cardinality and filter condition. It is not possible to specify join type characteristics in the filter. The details are described in topic CDS DDL - CDS Projection View, filter . When exposing a CDS association with a filter, an alternative element name alias using AS is mandatory. Here's an example: _toAssoc[to exact one:field='1'] as filteredAssoc
A CDS association can be exposed multiple times with various alternative element names. This makes it possible to use different filter conditions .
An exposed CDS association is part of the projection list. It is not, however, part of the result set, nor a component of the type defined in ABAP with respect to the CDS projection view.
Usage
No fields must be selected from locally defined associations. Path expressions are not supported.
Client dependency
A CDS projection view that is based on a client-independent CDS view must not contain an association to a client-dependent target view. Client dependency must not be changed by introducing a new association. This also applies to CDS view extensions later on, as this may lead to incompatibilities.

ABAP_RESTRICTIONS
Redirection of a newly defined association with the keyword REDIRECTED TO is not possible.
CDS compositions or to-parent associations cannot be defined.
ABAP_RESTR_END



Latest notes:

For an overview of all possible association targets of all CDS entities that can define associations, see Data Source Matrix.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
The following CDS projection view DEMO_SALES_PV_SO_ASSOC is a projection of the CDS view entity DEMO_SALES_CDS_SO. It defines associations to a CDS custom entity and a ABAP_CDS_V1_VIEW . These associations are exposed in the element list, but no fields are picked from the associations via a path expression.
DDLS DEMO_SALES_PV_SO_ASSOC
ABAP_EXAMPLE_END