Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing External Data →  ABAP Database Access →  ABAP SQL →  ABAP SQL - Reads →  SELECT clauses →  SELECT - INTO, APPENDING →  SELECT - INTO target 

SELECT, Inline Declarations

This example demonstrates inline declarations in the statement SELECT.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    TYPES BEGIN OF output_line.
    INCLUDE TYPE scarr AS scarr RENAMING WITH SUFFIX _scarr.
    INCLUDE TYPE spfli AS spfli RENAMING WITH SUFFIX _spfli.
    TYPES END OF output_line.
    TYPES output TYPE STANDARD TABLE OF output_line WITH EMPTY KEY.

    data carrier type scarr-carrid VALUE 'LH'.
    cl_demo_input=>request( CHANGING field = carrier ).

    SELECT *
       FROM scarr INNER JOIN spfli ON scarr~carrid = spfli~carrid
       WHERE scarr~carrid = @carrier
       ORDER BY scarr~carrid
       INTO TABLE @DATA(itab).

    SELECT scarr~*, spfli~*
       FROM scarr INNER JOIN spfli ON scarr~carrid = spfli~carrid
       WHERE scarr~carrid = @carrier
       ORDER BY scarr~carrid
       INTO TABLE @DATA(jtab).

    ASSERT itab = jtab.

    cl_demo_output=>write( name = 'OUTPUT1' data =
      VALUE output( FOR wa IN itab ( scarr = wa-scarr
                                    spfli = wa-spfli ) ) ).

    SELECT scarr~carrname,
           spfli~connid, spfli~cityfrom, spfli~cityto
       FROM scarr INNER JOIN spfli ON scarr~carrid = spfli~carrid
       WHERE scarr~carrid = @carrier
       ORDER BY scarr~carrid
       INTO TABLE @DATA(output2).

    cl_demo_output=>display( output2 ).

Description

The inline declarations of the first two SELECT statements create the same internal tables. The row type of the internal tables is a structure with the two substructures scarr and spfli that each have the columns of the two joined database tables as components. The substructures are resolved in a table comprehension in the output.

The inline declaration of the third SELECT statement creates an internal table with a non-nested row structure. The components of the row are determined directly using the columns specified in the SELECT list.