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, Create Internal Table as Target Area
The example demonstrates the creation of an internal table as a target area of the statement SELECT
.
Other versions:
7.31 | 7.40 | 7.54
Source Code
DATA: dbtab TYPE tabname VALUE 'SPFLI',
rows TYPE i VALUE 100.
cl_demo_input=>new(
)->add_field( CHANGING field = dbtab
)->add_field( CHANGING field = rows )->request( ).
DATA(out) = cl_demo_output=>new( ).
dbtab = to_upper( dbtab ).
TRY.
cl_abap_dyn_prg=>check_table_name_str(
val = dbtab
packages = 'SAPBC_DATAMODEL' ).
CATCH cx_abap_not_a_table.
out->display( 'Database table not found' ).
LEAVE PROGRAM.
CATCH cx_abap_not_in_package.
out->display(
'Only tables from the flight data model are allowed' ).
LEAVE PROGRAM.
ENDTRY.
TRY.
SELECT *
FROM (dbtab)
INTO TABLE NEW @DATA(table)
UP TO @rows ROWS.
assign table->* to field-symbol(<fs>).
out->display( <fs> ).
CATCH cx_sy_open_sql_db.
out->display( 'Error in ABAP SQL' ).
ENDTRY.
Description
Creates an internal table that is compatible with a database table in the INTO
clause and reads the first rows
(rows
) of the database table into the internal table. Since the data reference
table
is generically typed, access to the internal table can only take place using the field symbol <fs>
.
The method CHECK_TABLE_NAME_STR of the class CL_ABAP_DYN_PRG checks whether the database table specified exists and can be used.
See also the executable example for CREATE DATA
with explicit creation of the internal table.