ABAP - Keyword Documentation →  ABAP - Reference →  Processing External Data →  ABAP Database Accesses →  Open SQL →  Open SQL - Reads →  SELECT clauses →  SELECT - FROM →  SELECT - data_source → 

SELECT - FROM @itab

Quick Reference

Syntax

... @itab

Effect

Specifies an internal table itab, whose name must be prefixed with the @ character, as a data source of a query. The SELECT statement handles the internal table of the application server like a database table on the database. The ABAP types of the columns in the internal table are mapped to suitable built-in data types in ABAP Dictionary. If a column is declared with reference to a type in ABAP Dictionary, this type is used directly.

There are two different cases here:

In this case, the data of the internal table is accessed on the application server and the table is handled like a table in the table buffer. This is possible for all database platforms.
In this case, the data must be passed to temporary tables in the database before the query is actually executed. This option is not supported by all databases. If it is known statically that the data is required on the database, a syntax check warning occurs that can be hidden by the pragma ##db_feature_mode[itabs_in_from_clause]. If an attempt is made to pass data from the internal table to a database at runtime and the database does not support this, a handleable exception of the class CX_SY_SQL_UNSUPPORTED_FEATURE is raised.

The data in the internal table must not be passed to the database (or the statement can be executed on the application server) in precisely those cases where the SELECT statement meets the same conditions as when the table buffer is accessed in table buffering.

The ABAP types of the columns in the internal table are mapped to types in ABAP Dictionary. If a column is declared with reference to a type in ABAP Dictionary, this type is used directly.

The following conditions apply:

The data in the internal table is handled like data on the database even if it is not transported to the database. In particular, data with the type string declared using a reference to the built-in dictionary type SSTRING is handled like text fields with fixed lengths in which trailing blanks are ignored.

The internal table itab is always regarded as a cross-client table. The data type of the first column is never regarded as a client column, regardless of its data type.

Notes

Example

Uses a table of random numbers as a data source of a SELECT statement. The data is transported to the database for sorting and the statement can only be executed in database systems where sorting is supported.

TYPES:
  BEGIN OF line,
    id     TYPE c LENGTH 1,
    number TYPE i,
  END OF line.

DATA itab TYPE HASHED TABLE OF line
          WITH UNIQUE KEY id.

IF NOT cl_abap_dbfeatures=>use_features(
         EXPORTING
           requested_features =
             VALUE #( ( cl_abap_dbfeatures=>itabs_in_from_clause ) ) ).
  cl_demo_output=>display(
    `System does not support internal tables as data source` ).
  RETURN.
ENDIF.

DATA(rnd) = cl_abap_random_int=>create(
  seed = CONV i( sy-uzeit ) min = 1 max = 100 ).
itab =  VALUE #(
  FOR i = 1 UNTIL i > 25
  ( id = substring( val = sy-abcde off = i len = 1 )
    number = rnd->get_next( ) ) ).

SELECT *
       FROM @itab AS numbers
       WHERE number > 50
       ORDER BY id
       INTO TABLE @DATA(result)
       ##db_feature_mode[itabs_in_from_clause].

cl_demo_output=>display( result ).

Example

Uses an internal table as the data source of an inner join of a SELECT statement. The data is transported to the database for the join and the statement can only be executed in database systems where joins are supported.

DATA itab TYPE HASHED TABLE OF scarr
          WITH UNIQUE KEY mandt carrid.

IF NOT cl_abap_dbfeatures=>use_features(
         EXPORTING
           requested_features =
             VALUE #( ( cl_abap_dbfeatures=>itabs_in_from_clause ) ) ).
  cl_demo_output=>display(
    `System does not support internal tables as data source` ).
  RETURN.
ENDIF.

itab =  VALUE #( ( carrid = 'LH' carrname = 'L.H.' )
                 ( carrid = 'UA' carrname = 'U.A.' ) ).

SELECT scarr~carrid, scarr~carrname, spfli~connid
       FROM @itab AS scarr
         INNER JOIN spfli ON scarr~carrid = spfli~carrid
       INTO TABLE @DATA(result)
       ##db_feature_mode[itabs_in_from_clause].

cl_demo_output=>display( result ).

Example

Uses a table with an elementary data type as the data source of two SELECT statements. The data is not needed on the database and the SELECT statements meet the requirements for table buffering. This means that the statements can be executed on all database systems. In the second SELECT statement, a syntax error would occur without the alternative column name number, since the inline declaration after INTO cannot create an internal table with the column name table_line. If the statements were modified in a such a way that they no longer met the requirements for table buffering (for example by adding the addition DISTINCT), it would not be possible to execute them on all database systems.

DATA itab TYPE SORTED TABLE OF i WITH UNIQUE KEY table_line.
itab =  VALUE #( ( 1 )
                 ( 2 )
                 ( 3 ) ).

DATA result1 LIKE itab.
SELECT table_line
       FROM @itab AS numbers
       INTO TABLE @result1.
cl_demo_output=>write( result1 ).

SELECT table_line AS number
       FROM @itab AS numbers
       INTO TABLE @DATA(result2).
cl_demo_output=>display( result2 ).