SAP EXEC HOST ABAP Statements

Get Example source ABAP code based on a different SAP table
  



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. For identification purposes, the data object name has a colon (:) directly in front of it. 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.

Only flat elementary fields and flat structures with elementary components can be used 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.
• STRUCTURE EXEC SQL

In a SELECT statement, the SAP-specific addition STRUCTURE can be specified 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 data objects 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.



Latest notes:The indicator variables provided in the SAP standard, which
can be specified after an operand to identify null values, can be specif ied in static Native SQL by a host variable that has to be of an external data type INT2.



Example ABAP Coding
Like the example for literals;
the row to be read is here also specified using host variables. 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.

Return to menu