Use indicator variables in COBOL applications that use SQL

An indicator variable is a two-byte integer (PIC S9(m) USAGE BINARY, where m is from 1 to 4).

You can also specify an indicator structure (defined as an array of halfword integer variables) to support a host structure. On retrieval, an indicator variable is used to show whether its associated host variable has been assigned a null value. On assignment to a column, a negative indicator variable is used to indicate that a null value should be assigned.

Indicator variables are declared in the same way as host variables, and the declarations of the two can be mixed in any way that seems appropriate to the programmer.

Example

Given the statement:

  EXEC SQL FETCH CLS_CURSOR INTO :CLS-CD,
                                 :NUMDAY :NUMDAY-IND,
                                 :BGN :BGN-IND,
                                 :ENDCLS :ENDCLS-IND
  END-EXEC.

The variables can be declared as follows:

  EXEC SQL BEGIN DECLARE SECTION END-EXEC.
  77 CLS-CD     PIC X(7).
  77 NUMDAY     PIC S9(4) BINARY.
  77 BGN        PIC X(8).
  77 ENDCLS     PIC X(8).
  77 NUMDAY-IND PIC S9(4) BINARY.
  77 BGN-IND    PIC S9(4) BINARY.
  77 ENDCLS-IND PIC S9(4) BINARY.
  EXEC SQL END DECLARE SECTION END-EXEC.
Related reference
References to variables