In general, the clause INDEXED BY
should be used whenever possible when handling COBOL tables. If it’s not possible, then avoid using
a numeric display variable to access the table’s elements. Instead, use a BINARY
/COMP
variable, which the processor can
handle more efficiently.
Noncompliant code example
01 SUBS PIC 9(5).
01 INVENTORY-RECORD.
05 Field-A PIC X OCCURS 10000 TIMES.
...
PERFORM VARYING SUBS FROM 1 BY 1 UNTIL SUBS > 10000
MOVE ITEM1 TO Field-A (SUBS) *> Noncompliant
END-PERFORM.
Compliant solution
01 SUBS PIC 9(5) COMP.
01 INVENTORY-RECORD.
05 Field-A PIC X OCCURS 10000 TIMES.
...
PERFORM VARYING SUBS FROM 1 BY 1 UNTIL SUBS > 10000
MOVE ITEM1 TO Field-A (SUBS)
END-PERFORM.
or
01 INVENTORY-RECORD.
05 Field-A PIC X OCCURS 10000 TIMES INDEXED BY IDX1.
...
PERFORM VARYING IDX1 FROM 1 BY 1 UNTIL IDX1 > 10000
MOVE ITEM1 TO Field-A (IDX1)
END-PERFORM.