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 Structure as Target Area
The example demonstrates the creation of an structure 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.
dbtab = 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 NEW @DATA(row)
UP TO @rows ROWS.
ASSIGN row->* TO FIELD-SYMBOL(<fs>).
out->write( <fs> ).
ENDSELECT.
out->display( ).
CATCH cx_sy_open_sql_db.
out->display( 'Error in ABAP SQL' ).
ENDTRY.
Description
Creates a work area that is compatible with a database table in the INTO
clause and reads the first rows
(rows
) of the database table into this work area using a
SELECT
loop. Since the data reference row
is typed generically, access to the work area 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 structure.