Ansicht
Dokumentation

ABENCDS_SIMPLE_CASE_EXPRESSION_V2 - CDS SIMPLE CASE EXPRESSION V2

ABENCDS_SIMPLE_CASE_EXPRESSION_V2 - CDS SIMPLE CASE EXPRESSION V2

TXBHW - Original Tax Base Amount in Local Currency   Addresses (Business Address Services)  
This documentation is copyright by SAP AG.
SAP E-Book

- CDS View Entity, simple_case_expr

... CASE operand
         WHEN operand1 THEN result1
        $[WHEN operand2 THEN result2$]
         ...
        $[ELSE resultn$]
    END ...


Effect

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 specified after ELSE is returned. If ELSE is not specified, the result is the zero value.

  • For operand, operand1, operand2, and for result1, result2, the following operands can be specified:

  • Fields of a data source data_source of the current CDS view entity

  • A further case distinction

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/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 example shows a CDS view entity with two case distinctions.

Example

The example shows a CDS view entity with two case distinctions using amount and quantity fields.






BAL_S_LOG - Application Log: Log header data   BAL Application Log Documentation  
This documentation is copyright by SAP AG.

Length: 8500 Date: 20240424 Time: 010030     sap01-206 ( 71 ms )