ABAP Keyword Documentation → ABAP - Reference → Processing External Data → ABAP - Database Accesses → Native SQL → EXEC SQL
EXEC SQL - Literals and Host Variables
You can specify appropriate literals in ABAP syntax at suitable read positions in Native SQL statements.
Host variables are global or local variables declared in the ABAP program that are used in operand positions of
Native SQL statements. For identification purposes, the variable name has a colon
(:
) directly in front of it. Instead of specifying a variable itself, you
can also specify a field symbol to which the variable is assigned. You cannot specify dereferenced data reference variables.
You can use only flat elementary fields and flat structures with elementary components as host variables, with one
exception. If a structure is listed in a Native SQL
statement after INTO
, it is converted by the Native SQL interface as if its components were listed as individual fields separated by commas.
In a SELECT
statement, you can specify the SAP-specific addition STRUCTURE
between INTO
and an individual host variable. This addition has the effect
that the host variable is treated 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 occurs.
When assignments are made between host variables and fields in database tables, the Native SQL interface passes a description of type, size, and storage location of the ABAP fields used to the database system. The actual database accesses and conversions are usually executed directly by the corresponding operations of the database system. In some cases, however, the Native SQL interface executes extensive compatibility checks.
The conversion rules between ABAP data types and types of database columns are listed in the programming interface manuals of the appropriate database system, both for write accesses
(INSERT
, UPDATE
) and for read (SELECT
) accesses. These conversion rules apply also to the input and output parameters for
database procedures. Any combinations listed there are undefined and should not be used.
Other versions: 7.31 | 7.40 | 7.54
Note
The indicator variables provided in the SAP standard, which can be specified after an operand to identify null values, can be specified in Native SQL by a host variable that has to be of an external data type INT2.
Example
Reading a row from the database table SPFLI using Native SQL and host variables.
If a row was found, sy-subrc
is set to 0; if not, it is set to 4. The addition
STRUCTURE
is specified after INTO
. However, this
is not necessary since wa
can be identified statically as a structure. The
structure wa
is handled in the INTO
clause as if all subfields were listed separately: INTO :wa-cityfrom, :wa-cityto
.
PARAMETERS: p_carrid TYPE spfli-carrid,
p_connid TYPE spfli-connid.
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 = :p_carrid AND connid = :p_connid
ENDEXEC.