Ansicht
Dokumentation

ABENSQL_SIMPLE_CASE - SQL SIMPLE CASE

ABENSQL_SIMPLE_CASE - SQL SIMPLE CASE

ABAP Short Reference   BAL Application Log Documentation  
This documentation is copyright by SAP AG.
SAP E-Book

- sql_simple_case

... CASE sql_exp
         WHEN sql_exp1 THEN result1
        $[WHEN sql_exp2 THEN result2$]
         ...
        $[ELSE resultn$]
    END ...


Effect

Simple case distinction (simple case) in . This SQL expression compares the values of the operand sql_exp with the operands sql_exp1, sql_exp2, ..., and returns 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 null value.

The operands sql_exp, sql_exp1, sql_exp2, ..., and the results result1, result2, ... can be any SQL expressions. They can have any dictionary types except ACCP, DF16_SCL (obsolete), DF34_SCL (obsolete), LCHR, LRAW, PREC, RAWSTRING, STRING, and GEOM_EWKB.

The data type of the operand sql_exp must be comparable with the data types of the operands sql_exp1, sql_exp2, .... If this is not the case, a static specification raises a syntax error and a dynamic specification raises an exception of the class CX_SY_DYNAMIC_OSQL_SEMANTICS. The results must also be compatible to produce a common result type: The data types result1, result2, ... must be either the same or the data type must be able to completely represent the value of all other data types. The result has the dictionary type of the specification with the greatest value range.

If an operand of a comparison has the null value, the result of this comparison is unknown.

Notes

  • If the case distinction is evaluated in the table buffer, the order of processing is preserved and there is no termination when an operand is evaluated whose condition is not true.
  • If an operand of a simple CASE expression is an SQL expression, the syntax check is performed in a strict mode that handles the statement more strictly than the regular syntax check.

Example

Conversion of the distances specified in miles to kilometers. The conversion factor is specified as the host variable whose value has already been calculated using an SQL expression in a SELECT statement. This task could also be performed more generally in a subquery of a WITH statement.

SQL expressions, simple CASE






Addresses (Business Address Services)   ABAP Short Reference  
This documentation is copyright by SAP AG.

Length: 3310 Date: 20240425 Time: 011208     sap01-206 ( 59 ms )