ABAP Keyword Documentation → ABAP - Dictionary → ABAP CDS in ABAP Dictionary → ABAP CDS - Data Definitions → ABAP CDS - DDL for Data Definitions → 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. The case distinction compares the values of operand operand with operands operand1, operand2, ... and produces the operand result as the result after the first THEN for which the comparison is true. 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, ... :
- Literals without a domain prefix
- 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 result1, result2, ...:
- Literals without a domain prefix
- 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 with operand1, operand2, ... When the CDS view is activated, a result type is determined from the operands result1, result1, ... that covers their types. The operands must be compatible with each other.
The operands cannot have the type LCHR, LRAW, STRING, RAWSTRING, or GEOM_EWKB.
Notes
- The SQL standard dictates the result of a case distinction, but not the order in which the operands are evaluated. Potentially, the result may even be evaluated before the associated condition. This means that any expressions specified as operands must have no side effects and must not be dependent on each other.
- On the SAP HANA database, operands are evaluated in parallel for reasons of optimization. The order in which the operands are evaluated is undefined. If an exception is raised when am operand is evaluated, the entire case distinction is canceled. Here, it does not matter which conditions apply and the order in which they are noted. From this reason, it is advisable not to use any exceptions in expressions specified as operands. More information can be found in the HANA-specific SQL documentation.
Example
Case distinction in a SELECT list.
when '01' then 'customer'
when '02' then 'supplier'
end as partner_role