Saturday, December 5, 2020

Define CDS View with Joins

 

  • Define View with Joins

Defining a join between two data sources of a CDS view in ABAP CDS.using join expression.

Both inner and outer joins are possible:

  • A join between two data sources using INNER JOIN or just JOIN selects all entries of the data sources whose fields meet the ON condition.
  • A join between two data sources using LEFT OUTER JOIN selects all entries on the left side. A join between two data sources using RIGHT OUTER JOIN selects all entries on the right side. Entries that meet the ON condition have the same content as in the inner join. In entries that do not meet the ON condition, the elements on the right or left side have the null value that is set to a type-friendly initial value when the CDS view is used in Open SQL.

In nested join expressions, the order of the evaluation is specified by the arrangement of the ON conditions. From left to right, the most adjacent ON conditions are assigned to each JOIN and this expression is parenthesized implicitly. These implicit parentheses can be made explicit using actual parentheses, ( ). This is optional.

       Figure 3: Example of Define View with Join

In every join expression, a join condition cond_expr must be specified after ON.

 When specified, special rules apply to this condition.

Rules for conditions cond_exp in an ON condition of a join of a CDS view
in ABAP CDS:

1. All relational operators are allowed.
2. lhs expects a field of the data source data_source that represents
   the left side of the join.
3. A field of both data sources data_source of the join, a literal with
   optional domain prefix, a parameter, or a session variable can be
   specified for rhs (with the exception of the operator LIKE).
4. At least one comparison for equality between a field of the left 
   data source and a field of the right data source of the join must 
   be performed.
5. No path expressions or other expressions or function calls can be 
   specified.