MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

COBOL Search

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
SRAMAN
Beginner


Joined: 02 Dec 2002
Posts: 2
Topics: 1
Location: UK

PostPosted: Mon Feb 24, 2003 10:12 am    Post subject: COBOL Search Reply with quote

I need a help on getting SUBSCRIPT after we use SEARCH.
Let say I have a array (occurs 2000) as below

.. 03 WS-DATA OCCURS 2000.
.........05 WS-NUM PIC 9(4).
.........05 WS-NAME PIC X(50).

Let say we have INDEX defined for the above array.

Then I do SEARCH in the array for a given WS-NUM , say I got the succesful match for some INDEX value. But after coming out of COBOL SEARCH verb, I want to know the corresponding subscript , where the SEARCH has been succesfull. (Really, I went to use INDEX only because SEARCH cannot use subscript!.)

After doing SEARCH I want to know the subscript of the 'Matched array element' so that in subsequent portion of program I can use this subscript for PERFORMS etc, with out bothering about INDEX.

Any help how do achieve this.

Code:
Code:
Quote:
Back to top
View user's profile Send private message
SRAMAN
Beginner


Joined: 02 Dec 2002
Posts: 2
Topics: 1
Location: UK

PostPosted: Tue Feb 25, 2003 6:26 am    Post subject: Reply with quote

I am indeed using INDEX as you mentioned. But after that I
want to get the corresponding susbscript. Because, we are
doing hell a lot of processing to call another program, some
TSQ processing etc etc. For all these I would prefer to use
the subscript corresponding to the INDEX where my Search
was succesfull! (though I can use INDEX I dont want!)

In otherwords, I think I am looking for a formula to relate
INDEX and SUBSCRIPT for a given array which can be
expressed probably as function of 'n' - where 'n' is the bytes
in each array instance. So mathematically I need

s = f(i,n)

Where
s- subscript,
i - index from search,
n- size of a single array instance. Question is what is 'f'?

Thanks
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Tue Feb 25, 2003 6:59 am    Post subject: Reply with quote

SRAMAN,

Index represent displacement value of the table entry from the beginning of the table, subscript - occurrence # of the table entry.

For example if you have a list of month names each occupying 9 bytes, then the value of a subscript for the month of FEB would be 2, but the index would be 9. A formula to calculate index value when the occurrance and item length are known is:

Code:

Index = (Occurrance -1) * Item-Length


i.e

The index for feb =
Code:


INDEX VALUE FOR FEB = (2 - 1) * 9

INDEX VALUE FOR FEB = 1 * 9 = 9


Hope this helps...

cheers

kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Glenn
Beginner


Joined: 23 Mar 2003
Posts: 56
Topics: 3

PostPosted: Sun Mar 23, 2003 6:38 am    Post subject: Reply with quote

Usually on a set statement, the memory displacement value represented by index is converted into the subscript appropriate for the table in question.

However, keep in mind INDEX is always more efficient than subscript if you have a situation where accessing the tables don't require the conversion each time anyway for some reason....

One of my annoyances with COBOL is how inflexible indexes really are in the natural logic - you really have to manipulate the index at the memory level, like for a calculated subscript...

Kolusu illustrated the basic idea, but I'll go into it a little more deeper and specifically...

You have to start with the memory displacement that the table is at in memory. This is essentially done by assigning a pointer to the address of the whole table. This corresponds to the location of the first element. So if we use a little algebra:

Code:

L(1) = D
where L = location of element
    and D = memory displacement of the table


We have to remember that memory is all linear in memory, and the table is stored in continguous bytes in memory, so we can continually add the size of the memory block, as Kolusu explains... to extend it out and create a formula...

Code:

L(1) = D + S * 0
L(2) = D + S * 1
L(3) = D + S * 2...
So
L(x) = D + S(x-1)...
where L = location of element
    and D = memory displacement of the table
    and S = size of the table element
    and x =  desired element of the table


Unfortunately with the vagaries of COBOL you have to define the pointer value and then redefine the pointer to S9(8) BINARY when you do this...unfortunately I've had very not good success with doing this to indexes defined with tables (think TABLE1 OCCURS 50 TIMES INDEXED BY TABLE1-NDX).

Didn't try to equate the indexes back and forth, when this came up I didn't try too hard - better to get the job done than get it completely efficient if you can deliver it within specs - so subscript ends up easier unless there's a case where it really is less efficient to do so. I remember a case I read about where a 24 hr (and still running) job was cut down to 3 hrs from converting subscript use to indexes...so it does matter at some point...

Hope this helps.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group