Null or truncation indicator variables and indicator tables in C and C++ embedded SQL applications

For each host variable that can receive null values, you must declare indicator variables as a short data type.

An indicator table is a collection of indicator variables to be used with a host structure. An indicator table must be declared as an array of short integers. For example:

   short ind_tab[10];

The preceding example declares an indicator table with 10 elements. It can be used in an SQL statement as follows:

   EXEC SQL SELECT id, name, years, salary
        INTO :staff_record INDICATOR :ind_tab
        FROM staff
        WHERE id = 10;
The following lists each host structure field with its corresponding indicator variable in the table:
staff_record.id
ind_tab[0]
staff_record.name
ind_tab[1]
staff_record.info.years
ind_tab[2]
staff_record.info.salary
ind_tab[3]
Note: An indicator table element, for example ind_tab[1], cannot be referenced individually in an SQL statement. The keyword INDICATOR is optional. The number of structure fields and indicators do not have to match; any extra indicators are unused, as are extra fields that do not have indicators assigned to them.

A scalar indicator variable can also be used in the place of an indicator table to provide an indicator for the first field of the host structure. This is equivalent to having an indicator table with only one element. For example:

   short scalar_ind;

   EXEC SQL SELECT id, name, years, salary
             INTO :staff_record INDICATOR :scalar_ind
             FROM staff
             WHERE id = 10;

If an indicator table is specified along with a host variable instead of a host structure, only the first element of the indicator table, for example ind_tab[0], will be used:

   EXEC SQL SELECT id
             INTO :staff_record.id INDICATOR :ind_tab
             FROM staff
             WHERE id = 10;
If an array of short integers is declared within a host structure:
   struct tag
   {
     short i[2];
   } test_record;
The array will be expanded into its elements when test_record is referenced in an SQL statement making :test_record equivalent to :test_record.i[0], :test_record.i[1].