Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ABAP CDS: Inner Join vs Association

0 Kudos

Hi Experts

What is the difference between Inner join and Association in ABAP CDS ??

When we go for association in ABAP CDS and benefits of associations than inner join ??

Thanks

Naveen

1 REPLY 1

Former Member
0 Kudos

Hi Naveen,

  In association , both of inner join and left outer join can be defined by specifying association name in path expressions.

Refer the link below to differentiate association with inner join.

http://help.sap.com/abapdocu_740/en/index.htm?file=abencds_path_expression_attr.htm

Effect

Defines an association of the name assoc in a SELECT statement of a CDS view in ABAP CDS. An association joins the first elementary data source entity specified as the initial data source (after FROM using the ON condition cond_exp) with the data source entityspecified as the target data source (in the definition of the association). A data source entity can be a database table defined in ABAP Dictionary or a view. In the latter case, the view can be an external view or another CDS view.

An association of a SELECT statement can be accessed - in the same statement at all places where this is documented - by specifying the association name in path expressions. When a CDS view is activated with path expressions, the specified associations are converted to join expressions. The initial data source is shown on the left side and the target data source is shown on the right side. The ON condition of the association is added to the ON condition of the join. By default, the category of the join is determined by where the path expression is used:

  • After FROM, it is an inner join.
  • In all other locations, it is a left outer join.

This setting can be overwritten when specifying the association in a path expression using an attribute.When specifying the ON condition, the following special rules apply:

  • Fields of the initial data source, which are specified in the ON condition, must also be listed in the SELECT list of the currentSELECT statement. This ensures that a join expression can be built from the association (when used in a path expression). In theON condition, the field name should be prefixed by $projection and not by the name of initial data source.
  • The fields of the target data source must be prefixed in the ON condition by the name of the association (prefix assoc. separated by a period).

Notes

  • The syntax for defining and using associations is a high-value wrapping of the syntax for joins. Using associations instead of directly programming joins makes it easier to read the definition of a CDS view.
  • If an association is listed as a special case of a path expression in the SELECT list of the current SELECT statement, other CDS views can be used in the path expressions - provided that the current CDS view is used as the data source. Associations not listed in the SELECT list can only be used in path expressions of the current SELECT statement.
  • When a CDS view is activated, a join defined by an association is built for every use in a path expression and not for the definition of the association. No joins are constructed for associations that are not used in their CDS views.
  • Associations and join expressions can be used in a SELECT statement of a CDS view.

Thanks,

Kala L.