Hi,
This may be a repeated Question..But still i am not clear .So can you explain clearly...? The Main diff b/w INDEX & Subscript ?
Say,
01 Month.
02 M Occurs 12 times pic x(3). < - Values are JAN,FEB,MAR,APR,JUN,JUL,AUG,SEP,OCT,NOV.DEC.
77 sub pic x(3).
So if i want to Display only Jun monthe How?
Move 3 to SUB
Display M(SUB) Will do that ?
If i use index,then to Display JUN month,the IDX should be 18 ?
Please explain how the Displacement & Occurance comes into picture? Also Index can have value of ZERO? But Subscript should not have ZERO ?>
Subscript VS Index
- dick scherrer
- Global moderator
- Posts: 6268
- Joined: Sat Jun 09, 2007 8:58 am
Re: Subscript VS Index
Hello,
With a bit of test code you should run a few experiments.
If you do not understand what happens, post the code, what happened, and your doubt.
Someone will be able to clarify.
With a bit of test code you should run a few experiments.
If you do not understand what happens, post the code, what happened, and your doubt.
Someone will be able to clarify.
Hope this helps,
d.sch.
d.sch.
-
- Global moderator
- Posts: 3720
- Joined: Sat Dec 19, 2009 8:32 pm
- Skillset: Systems programming, SAS, COBOL, CICS, JCL, SMS, VSAM, etc.
- Referer: other forum
- Location: Dubuque, Iowa, USA
Re: Subscript VS Index
Code: Select all
01 WS-MONTH-TABLE.
05 MONTH-SUB PIC 9(02).
05 WS-MONTH-CONSTANTS PIC X(36) VALUE 'JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC'.
05 WS-MONTHS REDEFINES WS-MONTH-CONSTANTS
OCCURS 12
PIC X(03)
INDEXED BY MONTH-INDEX.
MOVE 6 TO MONTH-SUB.
SET MONTH-INDEX TO 6.
DISPLAY 'SUB: ' WS-MONTHS (MONTH-SUB).
DISPLAY 'IDX: ' WS-MONTHS (MONTH-INDEX).
Displacement and occurrence only come into the picture if you are dealing with dumps -- in which case you have to use the table element length to determine the actual occurrence number from the index value.
Actually, both indexes and subscripts can have values that are positive, zero, or negative and do not have to be within the number of table occurrences. However, using zero or negative values or exceeding the number of table occurrences vastly increases the likelihood of incorrect results, and an abend would be quite possible.
Re: Subscript VS Index
Hi,
Thanks..But my doubt is: in both SUB & Index case,we set value 6...so what is the diff b/w subscript(no of occurances) & Index (( Displacement )?????
Thanks..But my doubt is: in both SUB & Index case,we set value 6...so what is the diff b/w subscript(no of occurances) & Index (( Displacement )?????
-
- Global moderator
- Posts: 3720
- Joined: Sat Dec 19, 2009 8:32 pm
- Skillset: Systems programming, SAS, COBOL, CICS, JCL, SMS, VSAM, etc.
- Referer: other forum
- Location: Dubuque, Iowa, USA
Re: Subscript VS Index
An index allows you to use binary search on a table (SEARCH ALL) whereas a subscript does not. While indexes are slightly more efficient than subscripts, you would have to be accessing literally millions (possibly hundreds of millions) of table entries for there to be any noticeable difference on current machines.
My advice: accept that they both exist, pick one and use it (unless you're doing a binary search and must use an index), and forget about the question. You've already spent more time and energy worrying about the topic than your programs could possibly save in the next 20 years. To echo Perl enthusiasts, there is more than one way to do it in COBOL most of the time.
My advice: accept that they both exist, pick one and use it (unless you're doing a binary search and must use an index), and forget about the question. You've already spent more time and energy worrying about the topic than your programs could possibly save in the next 20 years. To echo Perl enthusiasts, there is more than one way to do it in COBOL most of the time.