Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing External Data →  ABAP Database Accesses →  Open SQL →  Open SQL - Overview 

Open SQL - Host Variables

Host variables are global or local variables (usually variables) declared in the ABAP program that are used in operand positions of Open SQL statements. Instead of the data object itself, a field symbol to which the data object is assigned can be specified. Dereferenced data reference variables can also be specified.

To identify a host variable, the names of named data objects or field symbols should always be directly prefixed by the escape character @. The escape character can only be used in Unicode programs, in which the program property fixed point arithmetic is activated. When the escape character is used, the syntax check is performed in a strict mode, which handles the statement more strictly than the regular syntax check.

Other versions: 7.31 | 7.40 | 7.54


Notes

  • ABAP data objects that are specified as enclosed dynamic tokens do not belong to the host variables and cannot be prefixed by the escape character @.

  • The escape character for host variables is independent of the general escape character for names !. The escape character ! can also be written in front of host variables that are already prefixed by the escape character @. However, this is not recommended.

  • Specifying host variables without the escape character @ is obsolete. The escape character @ must be specified in the strict modes of the syntax check from Release 7.40, SP05.

  • In addition to host variables, you can also specify suitable ABAP literals at the relevant read positions in Open SQL statements. Literals are usually handled like host variables. A literal cannot be prefixed and does not need to be prefixed by the escape character @.

  • When host variables with an escape character @ are specified, the syntax check is performed in a strict mode, which handles the statement more strictly than the regular syntax check.

Example

Specification of various host variables; the escape character @ is always used.

DATA carrid TYPE spfli-carrid. 
cl_demo_input=>request( CHANGING field = carrid ). 

DATA: BEGIN OF result, 
         carrid TYPE sflight-carrid, 
         connid TYPE sflight-connid, 
       END OF result. 
SELECT carrid, connid 
       FROM sflight 
       INTO CORRESPONDING FIELDS OF @result 
       WHERE carrid = @carrid. 
  ... 
ENDSELECT. 

FIELD-SYMBOLS <result> LIKE result. 
SELECT carrid, connid 
       FROM sflight 
       INTO CORRESPONDING FIELDS OF @<result> 
       WHERE carrid = @carrid. 
  ... 
ENDSELECT. 

DATA dref LIKE REF TO result. 
SELECT carrid, connid 
       FROM sflight 
       INTO CORRESPONDING FIELDS OF @dref->* 
       WHERE carrid = @carrid. 
  ... 
ENDSELECT.