Subscript VS Index



Unicenter CA-Easytrieve Plus Report Generator: CA's information retrieval and data management tool

Subscript VS Index

Postby debo » Fri Sep 03, 2010 5:36 pm

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 ?>
debo
 
Posts: 19
Joined: Sat Apr 17, 2010 5:26 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Subscript VS Index

Postby dick scherrer » Sat Sep 04, 2010 1:15 am

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.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Subscript VS Index

Postby Robert Sample » Sat Sep 04, 2010 3:39 am

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).
If you run this code, it should clear up a lot of confusion on your part. The examples you gave in your post would not display JUN for either subscript or 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.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Subscript VS Index

Postby debo » Sun Sep 05, 2010 1:23 pm

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 )?????
debo
 
Posts: 19
Joined: Sat Apr 17, 2010 5:26 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Subscript VS Index

Postby Robert Sample » Sun Sep 05, 2010 6:19 pm

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.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times


Return to CA-Easytrieve

 


  • Related topics
    Replies
    Views
    Last post