Indicator Variables Usage
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:
• The indicator variable can be a simple variable, an array element or a structure member that yields a short integer. For example:
short ind_var, *ind_ptr, ind_arr[5];
:var_1:ind_var
:var_2:*ind_ptr
:var_3:ind_arr[2]
• If the host variable associated with the indicator variable is a structure, the indicator variable should be an array of short 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 member of the structure, the second element to the second member, and so on. Array elements begin at subscript 0, and not at 1 as in other languages.
The following example uses the employee.dcl file that DCLGEN generated to retrieve values into a structure and null indicators into the empind array:
exec sql begin declare section;
exec sql include 'employee.dcl';
/* See above for description */
short empind[10];
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[0], :emprec.ename:empind[1],
:emprec.age:empind[2], :emprec.job:empind[3],
:emprec.sal:empind[4], :emprec.dept:empind[5],
from employee;