Null-indicator variables and null or truncation indicator variable tables in COBOL embedded SQL applications

To receive null values in embedded SQL applications, you must associate null-indicator variables with declared host variables in your embedded SQL applications. A null-indicator variable is shared by both the database manager and the host application.
Null-indicator variables in COBOL must be declared as a PIC S9(4) COMP-5 data type. The COBOL precompiler supports the declaration of null-indicator variable tables (known as indicator tables), which are convenient to use with group data items. They are declared as follows:
    01 <indicator-table-name>. 
        05 <indicator-name> pic s9(4) comp-5 
                            occurs <table-size> times. 
For example:
    01 staff-indicator-table. 
        05 staff-indicator pic s9(4) comp-5 
                           occurs 7 times. 
This indicator table can be used effectively with the first format of group item reference shown previously:
    EXEC SQL SELECT id, name, dept, job
      INTO :staff-record :staff-indicator 
      FROM staff WHERE id = 10 END-EXEC. 
Here, the precompiler detects that staff-indicator was declared as an indicator table, and expands it into individual indicator references when it processes the SQL statement. staff-indicator(1) is associated with staff-id of staff-record, staff-indicator(2) is associated with staff-name of staff-record, and so on.
Note: If there are k more indicator entries in the indicator table than there are subordinates in the data item (for example, if staff-indicator has 10 entries, making k=6), the k extra entries at the end of the indicator table are ignored. Likewise, if there are k fewer indicator entries than subordinates, the last k subordinates in the group item do not have indicators associated with them. Note that you can refer to individual elements in an indicator table in an SQL statement.