what is index or subscript in cobol. please give me brief ex

This is a Mainframe COBOL forum - you can post your queries on Mainframe COBOL, VS COBOL II, COBOL/370 , Enterprise COBOL

Moderators: dbzTHEdinosauer, Moderator Group

Post Reply
mainframe5
Active Member
Posts: 59
Joined: Tue Jul 24, 2007 7:25 pm

what is index or subscript in cobol. please give me brief ex

Post by mainframe5 » Fri Oct 10, 2008 7:02 pm

what is index or subscript in cobol. please give me brief example. what is major difference.thanks.

User avatar
muraligaru1
Moderator
Posts: 43
Joined: Sat Nov 11, 2006 7:03 pm

Post by muraligaru1 » Fri Oct 17, 2008 10:27 am

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.

Anuj Dhawan
Moderator
Posts: 1625
Joined: Sat Aug 09, 2008 9:02 am
Location: Mumbai, India

Post by Anuj Dhawan » Thu Nov 27, 2008 7:26 am

Hi,

You might like to visit this link as well:

http://publib.boulder.ibm.com/infocente ... 539569.htm
Regards,
Anuj

academyindia4

Topic deleted by Admin

Post by academyindia4 » Tue Jan 19, 2016 12:57 pm

<< Content deleted By Admin >>

lnpdavid
Member
Posts: 11
Joined: Tue Apr 28, 2009 8:48 pm
Location: Missouri USA

Post by lnpdavid » Fri Jan 22, 2016 9:37 pm

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.
David Earhart

academyindia4

Topic deleted by Admin

Post by academyindia4 » Sun Jan 24, 2016 12:04 am

<< Content deleted By Admin >>

academyindia4

Topic deleted by Admin

Post by academyindia4 » Mon Feb 01, 2016 10:19 pm

<< Content deleted By Admin >>

Post Reply

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



Other References
Mainframe Tools and others