Popular

COBOL INDEX, COBOL Sub-script - What is the difference between Index and Sub-script?

Subscript is the slot-no. or position in the table. Index is the displacement (in no of bytes)/actual address from the beginning of the array. Indexes are much faster than subscripts. Subscripts have to be converted internally to the address.
For example,
01 WS-TABLE.
  
05 WS-NAME OCCURS 5 TIMES PIC X(10).
----------------------- Subscript Index -----------------------
  
0        0    1        10
  
2        20
  
3        30
  
..       ..
-----------------------

Since index is much more efficient, you should declare a table and Index it.
01 WS-TABLE.
   05 WS-NAME OCCURS 5 TIMES PIC X(3) INDEXED BY I.

You use indexes just like subscripts, except for the fact that they are much faster and efficient.
PERFORM 1000-DISPLAY-DATA VARYING I FROM 1 BY 1 UNTIL I > 5
1000-DISPLAY-DATA.
   DISPLAY WS-NAME(I).

To increment or decrement an Index, SET Verb is used. SET I UP BY WS-LIT-ONE.
SET I TO 1.

You cannot MOVE data to Indexes. You also cannot perform Arithmetic Operations on an Index.

No comments:

Post a Comment