6. Embedded SQL for BASIC : BASIC Variables and Data Types : Variable Usage : Indicator Variables
 
Share this page                  
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:
The indicator variable can be a simple variable, an array element or a record member that yields a 2-byte integer (the word subtype). For example:
dcl word ind_var, ind_arr(5)
    :var_1:ind_var
    :var_2:ind_arr(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.
When you use 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 generated by the preprocessor begin at subscript 1 and not at subscript 0.
The following example uses the employee.dcl file generated by DCLGEN, to retrieve values into a record and null values into the array "empind".
exec sql include sqlca

exec sql begin declare section
    exec sql include 'employee.dcl'
        ! see above for description
     declare word 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(1), :emprec::ename:empind(2),        &
     :emprec::age:empind(3), :emprec::job:empind(4),          &
     :emprec::sal:empind(5), :emprec::dept:empind(6),         &
from employee
Note that there are three different types of colon qualifiers. The first colon indicates that a host variable is used. The second double-colon indicates that a structure member is used. The third colon is the indicator variable colon.