subscript : it indicates the no of occurences of the table and it is a normal cobol variable
index : it indicates the offset from the begining of the table and by using the three cobol verbs (set ,serch,perform)we will do the operations on the index variable .we cannot display the index variable like normal cobol variable .we will not declare the index variable in the working storage section.
You can create an index either with a particular table (using OCCURS INDEXED BY) or
separately (using USAGE IS INDEX).
05 TABLE-ITEM PIC X(8)
OCCURS 10 INDEXED BY INX-A.
The compiler calculates the value contained in the index as the occurrence number
(subscript) minus 1, multiplied by the length of the table element. Therefore, for
the fifth occurrence of TABLE-ITEM, the binary value contained in INX-A is (5 - 1) * 8,
If you use USAGE IS INDEX to create an index, you can use the index data item with
any table. For example:
77 INX-B USAGE IS INDEX.
. . .
PERFORM VARYING INX-B FROM 1 BY 1 UNTIL INX-B > 10
DISPLAY TABLE-ITEM (INX-B)
. . .
INX-B is used to traverse table TABLE-ITEM above, but could be used to traverse
other tables also.
You can increment or decrement an index-name by an unsigned numeric literal.
The literal is considered to be an occurrence number. It is converted to an index
value before being added to or subtracted from the index-name.
Initialize the index-name with a SET, PERFORM VARYING, or SEARCH ALL statement.
You can then also use it in SEARCH or relational condition statements. To change the
value, use a PERFORM, SEARCH, or SET statement.
Use the SET statement to assign to an index the value that you stored in the index
data item defined by USAGE IS INDEX. For example, when you load records into a
variable-length table, you can store the index value of the last record read in a data
item defined as USAGE IS INDEX. Then you can test for the end of the table by
comparing the current index value with the index value of the last record. This
technique is useful when you look through or process the table.
Because you are comparing a physical displacement, you can use index data items
only in SEARCH and SET statements or for comparisons with indexes or other index
data items. You cannot use index data items as subscripts or indexes.
In a two-dimensional table, the two subscripts correspond to the row and column
numbers. In a three-dimensional table, the three subscripts correspond to the
depth, row, and column numbers.
Subscript represents occurrence of the Table Entry. Subscript can be represented explicitly and implicitly. Explicitly means thru occurrence of the table entry; implicitly means thru a data name. That data name should be defined as an independent item in the Working Storage Section. The most efficient definition of Subscript is Full-Word binary.
An Index is assigned to specific table thru INDEXED BY clause. Internally is represented by Index Register which is Full-Word binary. Specific index name can be used to reference a field from the table to which that index is assigned to index represents displacement value of the table entry from the beginning of the table.
Index represent displacement value of the table entry from the beginning of the table, subscript - occurrence of the table entry. To calculate the displacement of the table entry from its beginning when subscript is used takes 16 additional instructions from the system because of that the usage of the index is more efficient.