Declaring host variables and indicator variables in Fortran

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:
    • When you declare a character host variable, do not use an expression to define the length of the character variable. You can use a character host variable with an undefined length (for example, CHARACTER *(*)). The length of any such variable is determined when the associated SQL statement executes.
    • Host variables must be scalar variables; they cannot be elements of vectors or arrays (subscripted variables).
    • Be careful when calling subroutines that might change the attributes of a host variable. Such alteration can cause an error while the program is running.
    • 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.