what is index or subscript in cobol. please give me brief ex
Moderators: dbzTHEdinosauer, Moderator Group
-
- Active Member
- Posts: 59
- Joined: Tue Jul 24, 2007 7:25 pm
what is index or subscript in cobol. please give me brief ex
what is index or subscript in cobol. please give me brief example. what is major difference.thanks.
- muraligaru1
- Moderator
- Posts: 43
- Joined: Sat Nov 11, 2006 7:03 pm
Subscript - 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 ).
These are interview questions. please post them in interview questions forum.
I would suggest you to complete the cobol course.
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 ).
These are interview questions. please post them in interview questions forum.
I would suggest you to complete the cobol course.
-
- Moderator
- Posts: 1625
- Joined: Sat Aug 09, 2008 9:02 am
- Location: Mumbai, India
Hi,
You might like to visit this link as well:
http://publib.boulder.ibm.com/infocente ... 539569.htm
You might like to visit this link as well:
http://publib.boulder.ibm.com/infocente ... 539569.htm
Regards,
Anuj
Anuj
In addition to the explanation above, the indexing method of table (or array) handling has some coding benefits.
First - The SEARCH verb can be used to lookup data in the table.
Second - A SEARCH verb by itself will sequentially lookup information in the table. This is good for when the key to the data is unstructured or not in sequence.
Third - A SEARCH ALL can be used to do a binary search when the key to the data is in ascending (or descending) order.
If you are using subscripting, and you want to do a binary search, you will have to code the routine to do that type of search. This is much more difficult than using a SEARCH ALL.
I'll leave it up to you to look into the manual for the setup of the table (or array) and the actual syntax.
Are you unfamiliar with a binary search? It is VERY FAST! A million entry table would only require looking at 20 entries, at most, to find what you're looking for. If you're doing a sequential search you'd have to look at an average of 500,000 entries - quite a difference.
First - The SEARCH verb can be used to lookup data in the table.
Second - A SEARCH verb by itself will sequentially lookup information in the table. This is good for when the key to the data is unstructured or not in sequence.
Third - A SEARCH ALL can be used to do a binary search when the key to the data is in ascending (or descending) order.
If you are using subscripting, and you want to do a binary search, you will have to code the routine to do that type of search. This is much more difficult than using a SEARCH ALL.
I'll leave it up to you to look into the manual for the setup of the table (or array) and the actual syntax.
Are you unfamiliar with a binary search? It is VERY FAST! A million entry table would only require looking at 20 entries, at most, to find what you're looking for. If you're doing a sequential search you'd have to look at an average of 500,000 entries - quite a difference.
David Earhart
FREE TUTORIALS
Tutorials
Free tutorials from mainframegurukul
- JCL Tutorial
Covers all important JCL concepts. - Cobol Tutorial
This tutorials covers all Cobol Topics from STRING to COMP-3. - DB2 Tutorial
DB2 Tutorial focuses on DB2 COBOL Programming. - SORT Tutorial
This Tutorial covers all important aspects of DFSORT with examples - CICS Tutorial
This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions
- Cobol Interview Questions
50+ Interview Questions - JCL Interview Questions
50+ Interview Questions - DB2 Interview Questions
100+ Interview Questions - CICS Interview Questions
70+ Interview Questions - VSAM Interview Questions
27 Interview Questions
Other References
Mainframe Tools and others
- XPEDITER Reference
Explains how we can debug a program - FILEAID Reference
Explains how to browse , edit and delete datasets - Change Man Reference
Quick Start tutorial on Changeman - Abend Reference
Important Abend codes explained - FaceBook Page
MainframeGurukul FaceBook Page - LinkedIn Page
MainframeGurkul Linkedin Page