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 →  Examples of SQL Expressions 

SQL Expressions, coalesce Function

This example demonstrates the coalesce function in SQL expressions.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA itab LIKE TABLE OF wa WITH EMPTY KEY.
    out = cl_demo_output=>new(
     )->begin_section( `OUTER JOIN with Coalesce` ).
    SELECT t1~a AS a1, t1~b as b1, t1~c AS c1, t1~d as d1,
           coalesce( t2~d, '--' ) AS d2,
           coalesce( t2~e, '--' ) as e2,
           coalesce( t2~f, '--' ) AS f2,
           coalesce( t2~g, '--' ) as g2,
           coalesce( t2~h, '--' ) AS h2
       FROM demo_join1 AS t1
         LEFT OUTER JOIN demo_join2 AS t2 ON t2~d = t1~d
       ORDER BY t1~d
       INTO CORRESPONDING FIELDS OF TABLE @itab.
    out->display( itab ).

Description

This example is an excerpt from the joins example. Here, the function coalesce is used to replace null values produced by an outer join with a different value.