Ansicht
Dokumentation

ABENCDS_SEARCHED_CASE_EXPR_V2 - CDS SEARCHED CASE EXPR V2

ABENCDS_SEARCHED_CASE_EXPR_V2 - CDS SEARCHED CASE EXPR V2

Vendor Master (General Section)   BAL Application Log Documentation  
This documentation is copyright by SAP AG.
SAP E-Book

- CDS View Entity, searched_case_expr

... CASE WHEN cds_cond1 THEN result1
        $[WHEN cds_cond2 THEN result2$]
        $[WHEN cds_cond3 THEN result3$]
          ...
        $[ELSE resultn$]
    END ...


Effect

Complex case distinction (searched case) in a SELECT statement of a CDS view entity. The case distinction evaluates the conditions cds_cond1, cds_cond2, ... and returns the first operand specified after THEN for which the comparison is true as result. If none of the conditions are true, the result specified after ELSE is selected. If ELSE is not specified, the result is the zero value.

The following rules apply to the conditions specified after WHEN:

  • All relational operators are allowed. That means that comparison operators, BETWEEN, LIKE, IS NULL and IS INITIAL are allowed.
  • The Boolean operators NOT, AND, and OR are allowed.
If a comparison operator is used, then lhs can also be an aggregate function, a case expression, an arithmetic expression, or a parameter.
If the relational operator IS NULL is used, then lhs can also be another case expression, an arithmetic expression, or a parameter.
If a comparison operator is used, then rhs can also be an aggregate function, a case expression, or an arithmetic expression.
for the operator LIKE, rhs must be a character literal.

element can be used to specify an element of the association target of the last CDS association of the path.

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/operand2 Amount Quantity Calculated Quantity Number
Amount amount calculated quantity calculated quantity calculated quantity
Quantity calculated quantity quantity calculated quantity calculated quantity
Calculated Quantity calculated quantity calculated quantity calculated quantity calculated quantity
Number calculated 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.

Notes

Example

The following CDS view entity has a complex case distinction in the SELECT list.

The program DEMO_CDS_SEARCHED_CASE_VE uses SELECT to access the view and shows the result.






General Data in Customer Master   BAL Application Log Documentation  
This documentation is copyright by SAP AG.

Length: 11247 Date: 20240423 Time: 181614     sap01-206 ( 94 ms )