EXEC SQL - INTO
7.31 | 7.40 | 7.54
SELECT ... INTO [STRUCTURE] :host1 [, host2] ...
In a native
FETCH statement specified
INTO clause can be specified to pass the read data to
host2, ... specified after the statement. If there are multiple rows in the results set, any one of the rows is read.
If a structure is specified as a host variable in after
INTO, it is transformed by the Native SQL interface as if its components
were specified as individual fields separated by commas. The addition
can be specified between
INTO and a single host variable. This addition has
the effect that the host variable is handled like a structure, even if a non-typed formal parameter
or a non-typed field symbol is specified. Otherwise, when multiple values are being passed, depending on the platform, either the first value only is passed or an exception is raised.
The SAP-specific addition
INTOis removed from the statement by the Native SQL interface before it can be passed to the database.
INTOcan only be used in statements introduced using
FETCH. In a statement introduced using
WITHto define a common table expression (CTE), for example,
INTOis not possible. In cases like this, either
OPENor ADBC (recommended) must be used.
As in the example for host variables. The addition
STRUCTURE is specified after
INTO. However, this is not necessary
wa is known statically as a structure. The structure
is handled in the
INTO clause as if all substrings were specified separately:
INTO :wa-cityfrom, :wa-cityto.
DATA: carrid TYPE spfli-carrid VALUE 'LH', connid TYPE spfli-connid VALUE '400'. cl_demo_input=>new( )->add_field( CHANGING field = carrid )->add_field( CHANGING field = connid )->request( ). DATA: BEGIN OF wa, cityfrom TYPE spfli-cityfrom, cityto TYPE spfli-cityto, END OF wa. EXEC SQL. SELECT cityfrom, cityto INTO STRUCTURE :wa FROM spfli WHERE mandt = :sy-mandt AND carrid = :carrid AND connid = :connid ENDEXEC. cl_demo_output=>display( wa ).