ABAP Keyword Documentation → ABAP Dictionary → ABAP CDS in ABAP Dictionary → ABAP CDS - Views → ABAP CDS - DDL Statements → ABAP CDS - DEFINE VIEW → ABAP CDS - SELECT → ABAP CDS - SELECT, Operands and Expressions → ABAP CDS - case_expr
ABAP CDS - simple_case_expr
Other versions:
7.31 | 7.40 | 7.54
Syntax
... CASE operand
WHEN operand1 THEN result1
[WHEN operand2 THEN result2]
...
[ELSE resultn]
END ...
Effect
Simple case distinction (simple case) in a SELECT statement of a CDS view in ABAP CDS. The case distinction compares the values of the operand operand with the operands operand1, operand2, ... in the order given and, as the result, provides the operand result after THEN for which the comparison is true for the first time. If no matches are found, the result specified after ELSE is selected. If ELSE is not specified, the result is the zero value.
- The following can be specified for operand:
- Fields of a data source data_source of the current CDS view
- Path expressions that identify a field of a data source data_source
- The following can be specified for operand1, operand2, ... :
- Fields of a data source data_source of the current CDS view
- Path expressions that identify a field of a data source data_source
- A further case distinction
- The following can be specified for result, result1, result2, ... :
- Fields of a data source data_source of the current CDS view
- Path expressions that identify a field of a data source data_source
- A further case distinction
The operand operand must be comparable operand1, operand2, ... When the CDS view is activated, a result type is determined from the operands result, result1, result2, ... that covers their types. The operands must be compatible with each other.
Example
Case distinction in a SELECT list.
when '01' then 'customer'
when '02' then 'supplier'
end as partner_role