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

How to traceback if I am getting SOC7 or SOC4 abend? List down the steps

5084


What is an in line perform? When would you use it? Anything else you wish to say about it.

836


Explain about different table spaces.

854


How do you define a variable of comp-1 and comp-2?

914


What is the default value(s) for an initialize? What keyword will allow for an override of the default?

863


What is the difference between goback, stop run and exit program in cobol?

1228


IF I mention stop run in CICS what happens?

2091


HOw can I get the negative sign while deduct high value from low value

2007


How do get the result of your program directly on your pc?

2069


What is report-item in COBOL?

894


Name some of the examples of COBOl 11?

2882


Differentiate cobol and cobol-ii. (Most of our programs are written in cobolii, so, it is good to know, how, this is different from cobol)?

842


What is the difference between a binary search and a sequential search? What are the pertinent cobol commands?

905


explain sorting techniques in cobol program?

889


What are the different rules to perform a Search?

815