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
How to get the last record in vsam file in cluster? And how can you get the ksds file records into your cobol program?
What are the different data types in cobol?
How do get the result of your program directly on your pc?
How to print 10 to 1 if the input have only 10 digit number?
how do you define single dimensional array and multidimensional array in your cobol?
1.give the details about WHEN OTHER. 2. how many form are available in evaluate.
explain sorting techniques in cobol program?
What are 77 levels used for?
What rules are to be followed while using the corresponding options?
I need to compare 3 variables(dates) and do some processing based on the earliest date. There could be more then 1 date record in any of the 3 fields. What is the best way to code this?
What is the utilization of copybook in cobol? Could we utilize a similar copybook?
How many sections are there in data division in COBOL?
what are decleratives in cobol?
What is rmode(any) ?
i have 10 names in an array and my name is one of them also array is not in sorted order i need to display my name using index how will i do this