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
What is link edit in cobol?
How do you define a variable of comp-1 and comp-2?
What are various search techniques in cobol? Explain.
What guidelines should be followed to write a structured cobol prgm?
How are the next sentence and continue different from each other?
How do you code cobol to access a parameter that has been defined in jcl? And do you code the parm parameter on the exec line in jcl?
Our issue is there seems to be a disconnect, or no link, between our SELECT statement and our SD. We had SELECT SORT-FILE and SELECT SORT-FILE ASSIGN TO SORTWRK. ASSIGN TO SORTWRK1 SORTWRK2 SORTWRK3 SORTWRK4. with SD SORT_FILE RECORD CONTAINS 7833 CHARACTERS. In either case, at run time, the system ignored our SORTWRK# DD statements and allocated 16 sort works with the SORTWK## naming convention. Any ideas why the system does not recognize the connection? We do not even need the SORTWRK DD statements. Thanks
Can we redefine the field of x(200) to less than 200?
Discuss about changing dataset name in proc.
example for sub strings ? and refernce modifications whit output pls
What are literals?
What is the difference between PIC 9.99 and 9v99 in COBOL?
how we sort two input files based on a common column and giving one o/p file please send me the coding logic?
input 1 input2 ouput1 output2 output 3 1 re 300 1 re 200 1 re 300 3 rc 500 1 re 200 2 rr 400 1 re 300 2 rr 400 1 rc 400 3 rc 500 1 rc 400 2 rr 700 2 rr 700 5 tt 900 5 tt 900 2 inputs r in flat file and output 1 is matched records,ouptput2 is unmatched of input1,output3 is unmatched of input2! how vl u get the output files using sequential order and to check with each and every records! let me know the procedure division ?
A table has two indexes defined. Which one will be used by the SEARCH?