3. Embedded SQL for COBOL : COBOL Data Items and Data Types : Variable Usage : Indicator Data Items
 
Share this page                  
Indicator Data Items
The syntax for referring to an indicator data item is the same as for an elementary data item, except that an indicator variable is always associated with another COBOL data item:
:data_item:indicator_item
or
:data_item indicator :indicator_item
Syntax Notes:
The indicator data item can be an elementary data item or an element of a table that yields a 2byte integer numeric data item. For example:
01 IND-1 PIC S9(4) USAGE COMP.
01 IND-TABLE.
  02 IND-2 PIC S9(4) USAGE COMP OCCURS 5 TIMES.
  :ITEM-1:IND-1
  :ITEM-2:IND-2(4)
If the data item associated with the indicator data item is a record, the indicator data item must be a table of indicators. In this case, do not subscript the table (see the following example).
When an indicator table is used, the first element of the table is associated with the first member of the record, the second element with the second member, and so on. Table elements begin at subscript 1.
The following example uses the employee.dcl file that DCLGEN generates, to retrieve values into a record and null values into the EMPIND table:
EXEC SQL BEGIN DECLARE SECTION END-EXEC.

* See above for description.

EXEC SQL INCLUDE 'employee.dcl' END-EXEC.
01 INDS.
 02 EMPIND PIC S9(4) USAGE COMP OCCURS 10 TIMES.
EXEC SQL END DECLARE SECTION END-EXEC.

EXEC SQL SELECT *
 INTO :EMPREC:EMPIND
 FROM employee
 END-EXEC
The example just shown generates code as though the following statement had been issued:
EXEC SQL SELECT *
INTO :ENO IN EMPREC:EMPIND(1),
     :ENAME IN EMPREC:EMPIND(2),
     :AGE IN EMPREC:EMPIND(3),
     :JOB IN EMPREC:EMPIND(4),
     :SAL IN EMPREC:EMPIND(5),
     :DEPT IN EMPREC:EMPIND(6),
  FROM employee
  END-EXEC