Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing External Data →  ABAP Database Access →  ABAP SQL →  ABAP SQL - Operands and Expressions →  ABAP SQL - SQL Expressions sql_exp →  sql_exp - sql_func →  ABAP SQL - Built-In Functions sql_func →  ABAP SQL - SQL Functions →  sql_exp - sql_coalesce 

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 executable 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.