Using host variables

Host variables let you transfer values between Adaptive Server and the application program.

Declare the host variable within the application program’s Embedded SQL declare section. Only then can you use the variable in SQL statements.

When you use the variable within an Embedded SQL statement, prefix the host variable with a colon. When you use the variable elsewhere in the program, do not use a colon. When you use several host variables successively in an Embedded SQL statement, separate them with commas or follow the grammar rules of the SQL statement.

The following example demonstrates correct host variable usage. PAR-1, PAR-2, and PAR-3 are declared as host variables and are then used as parameters to the myproc procedure:

exec sql begin declare section end-exec 
 01  PAR-1              PIC X(10). 
 01  PAR-2              PIC X(10). 
 01  PAR-3              PIC X(10). 
 exec sql end declare section end-exec 
 
 exec sql exec myproc :PAR-1, :PAR-2, :PAR-3 end-exec.

There are four ways to use host variables:

Regardless of their function, declare all host variables as described in “Declaring variables”. Following are instructions for using host variables.