Introduction to Join in CDS Views

In this tutorial, we are going to learn what in Join in CDS view, different type of joins we have with some examples. Let’s jump into it.

In CDS Views (Core Data Services) within SAP, a join is a way of combining data from multiple tables or views based on a related field (key). The purpose of using joins in CDS views is to create a unified data set from different sources, allowing you to retrieve and present related data together.

Types of Joins in CDS Views:
➯ Inner Join (INNER JOIN)
➯ Left Outer Join (LEFT OUTER JOIN)
➯ Right Outer Join (RIGHT OUTER JOIN)
➯ Cross Join (CROSS JOIN)

These joins control how records from different tables or views are matched and combined based on specific conditions. We will be learning join on Travel data

INNER JOIN

➯ Returns only the rows that have matching values in both tables.
➯ If there’s no match, the row will not appear in the result.
Save and Activate. Run CDS using F8.

LEFT OUTER JOIN

➯ Returns all rows from the left table (first table), and the matched rows from the right table (second table).
➯ If there’s no match, the result will contain NULL values for the columns from the right table.
Save and Active CDS view. Run using F8

RIGHT OUTER JOIN

➯ Returns all rows from the right table (second table), and the matched rows from the left table (first table).
➯ If there’s no match, the result will contain NULL values for the columns from the left table.

CROSS JOIN

➯ A CROSS JOIN returns the Cartesian product of both tables. It pairs every row from the first table with every row from the second table, leading to a potentially huge result set.
Use cautiously as it can result in a large number of rows
Save and Activate CDS view. Run using F8

Key Points:

Join condition: A join always requires a condition to match the columns from different tables.

Join type: Depending on your business requirement, you can choose the appropriate join type (INNER, LEFT OUTER, RIGHT OUTER, etc.) to determine how data should be matched.

Multiple joins: You can also perform multiple joins in a CDS view to link data from more than two tables.

Leave a Comment

Your email address will not be published. Required fields are marked *