Declaring host variables and indicator variables in assembler

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:

  1. Declare the variables according to the following rules and guidelines:
    • You can declare host variables in normal assembler style (DC or DS), depending on the data type and the limitations on that data type. You can specify a value on DC or DS declarations (for example, DC H'5'). The Db2 precompiler examines only packed decimal declarations.
    • 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.
  2. Optional: Define any associated indicator variables, arrays, and structures.