ABAP Keyword Documentation → ABAP − Reference → Processing External Data → ABAP Database Access → Native SQL → EXEC SQL - Embedded Native SQL → EXEC SQL
EXEC SQL - Host Variables
Other versions: 7.31 | 7.40 | 7.54
Syntax
... :dobj ...
Effect
Host variables are global or local data objects (usually variables) declared in the ABAP program that are used in operand positions of embedded
Native SQL statements.
Named data objects
can be identified by an escape character (a colon :
)placed
in front of the names of the data objects. Instead of the data object itself, a field symbol to which
the data object is assigned can be specified. Dereferenced data reference variables cannot be dereferenced. Depending on the operand position, the data objects can be
variables or
constants. Constant host variables are host constants.
Usually, only flat elementary fields and flat structures with elementary components can be used as host
variables. If a structure is specified after the INTO
clause by Native SQL, it is transformed by the Native SQL interface as if its components were specified as individual fields separated by commas.
In assignments between host variables and fields in database tables, a mapping takes place between the ABAP types and the database types. The ABAP types must match the database types. If they do not match, conversions must be made in the Native SQL interface. These conversions are platform-dependent and can raise exceptions.
Notes
- When passed to a host variable, a null value is transformed to its type-dependent initial value.
- The indicator variables provided in the SAP standard, which can be specified after an operand to identify null values, can be specified in static Native SQL by a host variable that has to be of an external data type INT2.
-
Host variables cannot be enumerated objects.
Example
Like the example for literals. Here, the row to read is specified using host variables.
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 :wa
FROM spfli
WHERE mandt = :sy-mandt AND
carrid = :carrid AND connid = :connid
ENDEXEC.
cl_demo_output=>display( wa ).