Indicator Variables
The syntax for referring to an indicator variable is the same as for a simple variable, except that an indicator variable is always associated with a host variable:
:host_variable:indicator_variable
or
:host_variable indicator :indicator_variable
Syntax Notes:
1. The indicator variable can be a simple variable, an array element or a record component that yields a 2-byte integer. The type indicator has already been declared by the preprocessor. For example:
ind_var, ind_arr[5] : Indicator;
:var_1:ind_var
:var_2:ind_arr[2]
2. If the host variable associated with the indicator variable is a record, the indicator variable should be an array of 2-byte integers. In this case the array should not be dereferenced with a subscript.
3. When using an indicator array, the first element of the array corresponds to the first member of the record, the second element with the second member, and so on. Indicator array elements begin at subscript 1, regardless of the lower bound with which the array was declared.
The following example uses the employee.dcl file generated by DCLGEN to retrieve values into a structure and null values into the array "empind".
exec sql include sqlca;
exec sql begin declare section
exec sql include 'employee.dcl';
var
empind : array[1..10] of Indicator;
exec sql end declare section;
exec sql select *
into :emprec:empind
from employee;
The above example generates code as though the following statement had been issued:
exec sql select *
into :emprec.eno:empind[1], :emprec.ename:empind[2],
:emprec.age:empind[3], :emprec.job:empind[4],
:emprec.sal:empind[5], :emprec.dept:empind[6],
from employee;