CDS TUTORIAL 4: SAP HANA ABAP MADE EASY

Share

For basics and other CDS view tutorial refer below Links

Join

Join in CDS View and Association

We can use different type of join in CDS View

  • Inner Join🡪Only matched data 
  • Left outer Join🡪Return all the records from left table and data matched from right no data from right table if there is no match
  • Right outer Join🡪 Return all the records from right table and data matched from left no data from left table if there is no match
  • Cross Join🡪It will work as inner join by default and there will no option to provide on condition

Example

  1. Create a CDS view with join as a template
  1. Activate and execute f8
  1. CDS with cross join🡪To check code behind the CDS view right click🡪Show SQL CREATE Statement it will be inner join

Association

Association is used to define relation b/w two tables.

Example.

  1. Create a CDS view by selecting template Define View with Association
  1. Let’s understand the code snippets in below 
  1. In the below example will see the SO header and SO item table associated with each other
  1. Let’s expose the CDS view inside the CDS itself by adding any field from the association

Right click on any column and click on Follow Association

  1. If we will not add _item only fields which is already exposed can be seen and there will be no option to exposed, it. Remove the _item from the code and execute it

Right click on any column and click on Follow Association

Cardinality

Cardinalities define a type of relationship between source and target table.

  • One-to-one
  • One-to-many

Important Point

  • Association work on demand basis hence it is also known as lazy joins. On demand means whenever the field defined under an association is accessed then association will work.
  • By Default, association will be a left outer join
  • By Default, cardinality will be [0..1]
  • Cardinality [Min..Max] Min cannot be * and Max cannot be 0

Path Expression 

  • By default, association in a CDS View is left outer join to make it inner join below eg. Can be refer
  • Calling an association enabled CDS View