Host-variable arrays in PL/I, C, C++, and COBOL

A host-variable array is an array in which each element of the array contains a value for the same column. The first element in the array corresponds to the first value, the second element in the array corresponds to the second value, and so on.

Start of changeHost-variable arrays can be referenced only in certain contexts: in a FETCH statement for a multiple-row fetch, in an INSERT statement for a multiple-row insert, or in a multiple-row MERGE statement. A host-variable array is designated in syntax diagrams as host-variable-array. End of change

Host-variable arrays are defined by statements of the host language as explained in DB2 Application Programming and SQL Guide.

The form of a host-variable array reference is similar to the form of a host variable reference. The reference :COL1:COL1IND is a host-variable array reference if COL1 designates an array. If COL1 designates an array, COL1IND must be a one dimensional array of small integer host variables. The dimension of the host-variable array must be less than or equal to the dimension of the indicator array. If an indicator array is not specified, no variable of the main host-variable array has an indicator variable.

In PL/I, C, C++, and COBOL, the syntax of host-variable-array is:

Read syntax diagram
>>-:host-identifier--+--------------------------------+--------><
                     | .-INDICATOR-.                  |   
                     '-+-----------+-:host-identifier-'   

In the following example, COL1 is the main host-variable array and COL1IND is its indicator array, If COL1 has 10 elements for fetching a single column of data for multiple rows of data, COL1IND must also have 10 entries.
   EXEC SQL FETCH CURSOR FOR 5 ROWS  INTO :COL1 :COL1IND;