What is the difference between index and subscript?

Answer Posted / manjunath

ubscript - Subscript is used to access elements in array.
Index also used for the same purpose.


Ex. 01 WS-GROUP.
05 WS-MONTH PIC X(3) OCCURS 12 TIMES.

To access 2nd month we sepcify WS-MONTH(2).
Value enclosed in brackets is called subscript ( in this case 2 ).


You can use INDEX for the same.

Ex. 01 WS-GROUP.
05 WS-MONTH PIC X(3) OCCURS 12 TIMES INDEXED BY WS-INDX.

In above example WS-INDX is a INDEX data item.
we can use this variable to access the elements in the array.

If you want to access 2nd element in the array. need to write the code as follows

SET WS-INDX TO 2.
DISPLAY " 2nd element in array " , WS-INDX.

An index is similar to a subscript, but internal value in the variables are different..
Normaly subscript refer the occurance number of the item in array. in our example that is 2. means to refer second occurance we use number 2.

In case of index, to refer second element of your array, it shoud contains value of displacement from the starting of the arrary. i.e, in our example we used SET command to set value in index field WS-INDX. after execution of this command
WS-INDX contain the value 3. To refer third element it should contains the value of
6, for fourth element it should contain the value of 9 ( in our example array element size is 3 ).

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

There are 5 fields and 1000 records in a file. Unload it into an array. Write the syntax for declaration and how will you unload it.

928


how do you define single dimensional array and multidimensional array in your cobol?

667


What is the difference between Call and a Link?

694


) what is the difference between AID and HANDLE AID?

1630


) how do u code after getting data?

1578






How can i load all the data from a file to Table (array) in cobol.How i manage the occurs clause with out reading the file.Any options avilable ? Please can any one help me it is urgent?

2093


What are INPUT PROCEDURE and OUTPUT PROCEDURE?

682


how we sort two input files based on a common column and giving one o/p file please send me the coding logic?

1646


System Testing for Mainframe Developers What is System Testing? integration testing ? what's the procedure ..

1586


Write a program to enter and display the names of students in a class using the occurs clause.

647


can anybody post me about file-aid and changemen tools pls and give me reference if any mainframe guys are there

1900


What are the different rules of SORT operation?

693


Explain the configuration section of a cobol program with examples of syntax.

655


What is the Purpose of Pointer in the string?

641


What is cobol?

741