Indicator Variables
The syntax for referring to an indicator variable is the same as for a simple variable, except that an indicator is always associated with a host variable:
:host_variable:indicator_variable
or
:host_variable indicator :indicator variable
Syntax Notes:
• The indicator variable can be a simple variable, an array element, or a record component that yields a 2-byte integer (short_integer). For example:
ind: Short_Integer; -- Indicator variable
ind_arr: array(1..10) of Short_Integer;
-- Indicator array
:var_1:ind_var
:var_2:ind_arr(2)
• If the host variable associated with the indicator variable is a record, then the indicator variable should be an array of 2-byte integers. In this case the array should not be dereferenced with a subscript.
• When you use an indicator array, the first element of the array corresponds to the first component of the record, the second element with the second component, and so on. Indicator array elements begin at subscript 1 regardless of the range with which the array was declared.
The following example uses the employee.dcl file generated by DCLGEN and the empind array to retrieve values and nulls into a structure.
exec sql include sqlca;
exec sql begin declare section;
exec sql include 'employee.dcl';
-- See above for description
empind: array(1..10) of short_integer;
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;