Indicator variables, indicator arrays, and host structure indicator arrays in COBOL

A COBOL indicator variable is a 2-byte binary integer. A COBOL indicator variable array is an array in which each element is declared as a 2-byte binary integer. You can use indicator variable arrays to support COBOL host structures.

You declare indicator variables in the same way that you declare host variables.

The following diagram shows the syntax for declaring an indicator variable in COBOL.

Read syntax diagramSkip visual syntax diagram0177variable-namePICTUREPICISS9(4)S9999USAGEISBINARYCOMPUTATIONAL-4COMP-4COMPUTATIONAL-5COMP-5COMPUTATIONALCOMPVALUEISconstant.

The following diagram shows the syntax for declaring an indicator array in COBOL.

Read syntax diagramSkip visual syntax diagramlevel-11 variable-namePICTUREPICISS9(4)S9999USAGEISBINARYCOMPUTATIONAL-4COMP-4COMPUTATIONAL-5COMP-5COMPUTATIONALCOMPOCCURSdimension2 TIMESVALUEISconstant.
Notes:
  • 1 level-1 must be an integer in the range 2–48.
  • 2 dimension must be an integer constant in the range 1–32767.

Examples

Example 1:
The following example shows declarations of three variables, with an indicator variable declaration for each host variable.

77 DAYVAR     PIC S9(4) BINARY.
77 BGNVAR     PIC X(8).
77 ENDVAR     PIC X(8).
77 DAYVAR-IND PIC S9(4) BINARY.
77 BGNVAR-IND PIC S9(4) BINARY.
77 ENDVAR-IND PIC S9(4) BINARY.

The following FETCH statement retrieves values from a table into the three host variables. If a table column value is null, Db2 sets the corresponding indicator variable to -1.

EXEC SQL FETCH CLS_CURSOR INTO  
                               :DAYVAR:DAYVAR-IND,
                               :BGNVAR:BGNVAR-IND,
                               :ENDVAR:ENDVAR-IND
END-EXEC.
Example 2:
The following example shows a declaration of a host structure, and a corresponding structure that contains an indicator array with the same number of elements as the number of variables in the host structure.

01 CLS.
   10 DAYVAR    PIC S9(4) BINARY.
   10 BGNVAR    PIC X(8).
   10 ENDVAR    PIC X(8).
01 CLS-IND-STRUCT.
   02 CLS-IND   PIC S9(4) BINARY OCCURS 3 TIMES.

The following FETCH statement retrieves values from a table into the host structure. If a table value is null, Db2 sets the corresponding indicator array element to -1.

EXEC SQL FETCH CLS_CURSOR INTO 
  :CLS:CLS-IND
END-EXEC.