Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing External Data →  ABAP Database Accesses →  Open SQL →  Open SQL - Read Accesses →  SELECT →  SELECT - result →  SELECT - select_list →  SELECT - col_spec →  SELECT - sql_exp →  sql_exp - sql_case 

sql_exp - sql_simple_case

Other versions: 7.31 | 7.40 | 7.54


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


Simple case distinction (simple case) in Open SQL. This SQL expression compares the values of operand operand with operands (one after the other) operand1, operand2, ... and returns operand result as the result after THEN (for which the comparison is true the first time). If no matches are found, the result specified after ELSE is selected. If ELSE is not specified, the result is the zero value.

The operands operand, operand1, operand2, ... and the results result1, result2, ... can be columns, host variables, literals, and any SQL expressions. Columns and expressions can have any dictionary types, except for ACCP, DF16_SCL (obsolete), DF34_SCL (obsolete), LCHR, LRAW, PREC, RAWSTRING, SSTRING, and STRING. Host variables and literals can have any ABAP types, except for string and xstring.

The data type of operand operand must be comparable with the data types of operands operand1, operand2, ... . If this is not the case, a statically specified type raises a syntax error and a dynamically specified type raises an exception of the class CX_SY_DYNAMIC_OSQL_SEMANTICS. The results must also be compatible to produce a common result type: Data types result1, result2, ... must be either the same or the data type must be able to fully represent the value of all other data types. The result has the dictionary type of the entry with the greatest value range.

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


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.