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.

Host-variable arrays can be referenced only as a simple reference in the following contexts. In syntax diagrams, host-variable-array designates a reference to a host-variable array.

  • In a FETCH statement for a multiple-row fetch. See FETCH statement.
  • In the FOR n ROWS form of the INSERT statement with a host-variable array for the source data. See INSERT statement.
  • In a MERGE statement with multiple rows of source data. See MERGE statement.
  • In an EXECUTE statement to provide a value for a parameter marker in a dynamic FOR n ROWS form of the INSERT statement or a MERGE statement. See EXECUTE statement.

Host-variable arrays are defined by statements of the host language, as explained in the following topics:

Tip: Host-variable arrays are not supported for assembler, FORTRAN, or REXX programs. However, you can use SQL descriptor areas (SQLDA) to achieve similar results in any host language. For more information see Defining SQL descriptor areas (SQLDA).

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.

Syntax

In PL/I, C, C++, and COBOL, a host-variable-array reference has the following syntax:

Read syntax diagramSkip visual syntax diagram: host-identifierINDICATOR: host-identifier

Example

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;