CDS Views Part 2: Joins, Expressions, CASE, CAST and Functions
Preview · a free account unlocks the full lesson
Build CDS views that do real work in the database: inner and left outer joins, WHERE conditions, CASE expressions, CAST to ABAP types, string and date functions, and session variables such as the system date.
In this lessonShow sectionsHide sections
Visual overview
Explanation
Part 1 created a single-table view; now we combine tables and calculate values directly in the database. CDS supports inner join, left outer join, right outer join, cross join, and union — far beyond what a classic SE11 view could do.
An inner join returns only rows with a match on both sides, such as an order item joined to its header, while a left outer join returns all rows from the left side, filling in NULL or initial values where there's no match, useful for items with optional text.
Each data source should get its own alias (as item, as head), with fields prefixed accordingly, and join conditions should use = on key fields — functions in ON conditions hurt performance, as covered in Part 10. For relations you'll want to reuse, associations (covered in Part 6) are generally preferable to hard joins.
A WHERE clause written into the view itself becomes a fixed filter applied for every consumer — for example, restricting to order type TA. Only rules that are always true belong in the view; filters specific to one consumer belong in that consumer's own SELECT instead.
CASE expressions come in two forms: a simple CASE, like case field when 'A' then ... else ... end, and a searched CASE, like case when cond then ... end, which is better suited to ranges or conditions spanning multiple fields. Every calculation needs a stable result type, so literals in different CASE branches should be cast to the same type — a common source of errors is CASE branches returning literals of different lengths.
Create a free account to keep reading
You have read the opening of this lesson. A free ERPClimb account unlocks the rest of it, every other lesson and topic, and your learning history, so you can pick up exactly where you stopped. No card needed.
- Full explanation
- Code example
- Real project scenario
- Common mistakes
- Best practices
- Interview angle
One tap with Google works too. Every topic keeps its first lesson open to everyone.
Keep exploring
Interview questions on this topic
Referenced SAP objects
Reviewed reference pages for the objects this page mentions.
Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.