Index in COBOL Table

Index

  • Displacement of an element from the start of the table is known as an index.
  • An index is declared with OCCURS clause using INDEXED BY clause.
  • Using SET and PERFORM varying option the value of an index can be changed.
Syntax:
01 WS-TABLE
     05 WS-A PIC A(10) OCCURS TIMES INDEXED BY I.

Set statement

SET statement is used to:
  • Change the index value.
  • Initialize, increment or decrement.
  • Locate elements in a table with Search and Search All.
Syntax:
SET I  J TO positive-number
SET I TO J
SET I TO 5
SET I J UP BY 1
SET J DOWN BY 5