ABAP - Keyword Documentation →  ABAP - Reference →  Processing External Data →  ABAP Database Accesses →  Native SQL →  EXEC SQL - Embedded Native SQL →  EXEC SQL → 

EXEC SQL - Host Variables

Host variables are global or local variables (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.

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

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 ).