SAP SQL COALESCE



Get Example source ABAP code based on a different SAP table
  


• COALESCE ABAP_OSQL_FUNC

ABAP_SQLFUNC - Coalesce Function

ABAP_SYNTAX
... COALESCE( sql_exp1, sql_exp2, ..., sql_expn ) ...

What does it do?
Calls the coalesce function as an SQL expression or operand of an expression in AB_SQL . The coalesce function can have a comma-separated list with at least two but no more than 255 arguments sql_exp1, sql_exp2, ..., sql_expn. This function returns the value of the first argument that does not have the null value. If every argument has the null value, the value of the last argument sql_expn is returned. A blank must be placed after the opening parenthesis and in front of the closing parenthesis.
The arguments can be any SQL expressions of all dictionary types except ACCP,
BEGIN_SECTION VERSION 5 OUT DF16_SCL (obsolete), DF34_SCL (obsolete),
END_SECTION VERSION 5 OUT LCHR, LRAW, PREC, RAWSTRING, STRING , and GEOM_EWKB. The data types of the arguments must either be the same or the data type of one argument must be able to fully represent the value of the other data types. The result has the dictionary type of the argument with the largest value range.



Latest notes:

The coalesce function can be used to assign a target object a user-defined value or the result of an expression when null values are read. The type-dependent initial value is assigned by default.
A maximum of ten coalesce functions can be nested.
A coalesce function is a short form of the following complex case distinction: CASE WHEN sql_exp1 IS NOT NULL THEN sql_exp1
WHEN sql_exp2 IS NOT NULL THEN sql_exp2
...
ELSE sql_expn
END
The coalesce function can be executed in the table buffer. Table buffering is not bypassed when the coalesce function is used.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
The first four CASE expressions return the null value, since no WHEN condition is met and no ELSE is specified. The result of the fifth CASE expression is not a null value and is returned by COALESCE.
ABEXA 01268
ABAP_EXAMPLE_END

ABAP_EXAMPLE_ABEXA
SQL Expressions, Coalesce Function
ABAP_EXAMPLE_END