SAP CDS SIMPLE CASE EXPRESSION V2



Get Example source ABAP code based on a different SAP table
  



ABAP_CDS_DDL - CDS View Entity, simple_case_expr

ABAP_SYNTAX
... CASE operand
WHEN operand1 THEN result1
$[WHEN operand2 THEN result2$]
...
$[${ELSE resultn $| ELSE NULL$}$]
END ...

What does it do?
Simple case distinction in a SELECT statement of a CDS view entity. The case distinction compares the values of operand operand with operands operand1 , operand2, ... and returns the first operand specified after THEN for which the comparison is true as result.
If no matches are found, the result is determined by the ELSE branch:
ELSE resultn returns the value resultn.
ELSE NULL returns the null value.
If ELSE is not specified, the result is the null value
For operand, operand1, operand2, and for result1, result2, the following operands can be specified:
Literals
Fields of a data source data_source of the current CDS view entity
Parameters
Session variables
Arithmetic expressions
Aggregate expressions
A further case distinction
Cast expressions
Built-in functions
SQL-based scalar functions
Path expressions that identify a field of a data source data_source
A reuse expression using $projection
The operand operand must be comparable with operand1, operand2, ... When the CDS view entity is activated, a result type is determined from the operands result1 , result2, .... The operands of the THEN and ELSE branches must be compatible with each other.
The operands can have any built-in data type except for LCHR, LRAW , STRING, RAWSTRING, or GEOM_EWKB.

Rules for Amounts and Quantities
The result data type of a case expression is determined by all THEN branches and the ELSE branch. If the result data type is a CDS amount field, a CDS quantity field, or a CDS calculated quantity, a reference annotation must be assigned. The following table shows how the result data type is calculated if one or more of the operands result1, result2, ... are amount and/or quantity fields. operand1/operand2Amount Quantity Calculated Quantity Number
Amountamount calculated quantitycalculated quantity calculated quantity
Quantitycalculated quantityquantitycalculated quantity calculated quantity
Calculated Quantitycalculated quantity calculated quantity calculated quantitycalculated quantity
Numbercalculated quantity calculated quantity calculated quantity number
It is not mandatory that the operands and the result point to the same reference field.
The following rules apply to amount fields of data type CURR:
fields of data type CURR are compatible only to other amount fields of data type CURR and only if they have exactly the same number of decimal places.
To combine an amount field of data type CURR with a field of another data type, a conversion to data type DECFLOAT34 using the conversion function CURR_TO_DECFLOAT_AMOUNT is required.



Latest notes: