You can use host variables, host variable arrays, and host
structures in SQL statements in your program to pass data between DB2® and your application.
Procedure
To declare host variables, host variable arrays, and
host structures:
- Declare the variables according to the following rules
and guidelines:
- If you specify the ONEPASS SQL processing option, you must explicitly
declare each host variable and each host variable array before using
them in an SQL statement. If you specify the TWOPASS precompiler option,
you must declare each host variable before using it in the DECLARE
CURSOR statement.
- If you specify the STDSQL(YES) SQL processing option, you must
precede the host language statements that define the host variables
and host variable arrays with the BEGIN DECLARE SECTION statement
and follow the host language statements with the END DECLARE SECTION
statement. Otherwise, these statements are optional.
- Ensure that any SQL statement that uses a host variable or host
variable array is within the scope of the statement that declares
that variable or array.
- If you are using the DB2 precompiler,
ensure that the names of host variables and host variable arrays are
unique within the program, even if the variables and variable arrays
are in different blocks, classes, procedures, functions, or subroutines.
You can qualify the names with a structure name to make them unique.
- Optional: Define any associated indicator variables,
arrays, and structures.