Indicator Variables Usage
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
• The indicator variable can be a simple variable or an array element that yields a 2-byte integer. For example:
integer*2 indvar, indarr(5)
:var_1:indvar
:var_2:indarr(2)
• If the host variable associated with the indicator variable is a structure, the indicator variable should be an array of 2-byte integers. In this case the array should not be dereferenced with a subscript.
• When an indicator array is used, the first element of the array corresponds to the first member of the structure, the second element with the second member, and so on. Array elements begin at subscript 1.
The following example uses the "employee.dcl" file that DCLGEN generates to retrieve non-null values into a structure and null values into the "empind" array:
exec sql begin declare section
exec sql include 'employee.dcl'
integer*2 empind(10)
exec sql end declare section
exec sql select *
1 into :emprec:empind
2 from employee
The previous example generates code as though the following statement had been issued:
exec sql select *
1 into :emprec.eno:empind(1), :emprec.ename:empind(2),
2 :emprec.age:empind(3), :emprec.job:empind(4),
3 :emprec.sal:empind(5), :emprec.dept:empind(6),
4 from employee