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 

Query on SEARCH ALL

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


Joined: 28 Nov 2006
Posts: 143
Topics: 48

PostPosted: Wed Apr 14, 2010 1:21 am    Post subject: Query on SEARCH ALL Reply with quote

I am having a EMPL table with OCCURS 99 times and ASCNEDING KEY EMPL-ID and INDEXED BY REC-CNT.

Initially in my cobol program I am loading this table reading File 1. File 1 is having 3 records with EMPL-ID's 1,2,3 respectively for each record. So 3 occurences get filled in the EMPL table in ascending order of EMPL-ID.

After this I am searching the EMPL table on EMPL-ID say for example EMPL-ID = 3 using SEARCH ALL. But the equality condition is not satisfying and AT END condition is getting executed.

I would like to know is there any limitaion on SEARCH ALL that all the occurences of table need to be filled completely and there should not be empty occurences. Or is there any other way using SEARCH ALL to get the desired result.
_________________
Thanks
Madhu Sudhan
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Wed Apr 14, 2010 7:16 am    Post subject: Reply with quote

if you would bother to read the programmers application guide and the programmers reference,
or even searched the board
before bothering us with your question on the basics of SEARCH ALL,
you would have found that yes,
if you have a fixed length table,
all items need to be appropriately populated.

it is just as quick to use a SEARCH
or
just PERFORM incrementing the INDEX UNTIL find or end of items maintained by a counter of actual items in the table.

than using a SEARCH ALL with less than 128 items ,
especially a fixed length table that is not completely populated.
A SEARCH ALL performs best with a properly populated ODO table.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
psmadhusudhan
Beginner


Joined: 28 Nov 2006
Posts: 143
Topics: 48

PostPosted: Wed Apr 14, 2010 9:23 am    Post subject: Reply with quote

Thanks Dick for your reply Smile
_________________
Thanks
Madhu Sudhan
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Wed Apr 14, 2010 10:09 am    Post subject: Reply with quote

psmadhusudhan,

You need to initialize the table to HIGH-VALUES for SEARCH ALL to work properly. when initializing an array to be used in a binary or sequential search for which the data is known to be in ascending sequence, the unused portion of the array must be initialized to high values to get a binary search to function properly. A sequential search will work without this, but it can be made more efficient when a "not found" condition is being executed by exiting the search when the array key is > the search key.

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


Joined: 02 Dec 2002
Posts: 93
Topics: 0
Location: Orlando, FL

PostPosted: Wed Apr 14, 2010 1:12 pm    Post subject: Reply with quote

dbzTHEdinosauer wrote:

it is just as quick to use a SEARCH
or
just PERFORM incrementing the INDEX UNTIL find or end of items maintained by a counter of actual items in the table.

than using a SEARCH ALL with less than 128 items ,


Begging to differ, but, that is not my understanding.

Given an equal distribution of search argument values, the AVERAGE number of comparisons for an ordered table when doing a SEQUENTIAL search is n/2, while the AVERAGE number of comparisons for an ordered table when doing a BINARY search is Log2(n)-1. Worst case ( a not found condition beyond the last table entry ) for a such a SEQUENTIAL table would be n, while the worst case for a BINARY search would be Log2(n)
Assuming an equal distribution of search argument values, and a properly populated ( ascending or descending order ) table , a binary search will outperform a sequential search for any table with 7 entries or more ( sequential search average = n/2 = 4 while a binary search average = log2(n) = 3 ).

Obviously, if the distribution of search arguments is NOT equal ( e.g. employee state code for a company with headquarters in Massachusetts ), it may be far more efficient to use a table ordered on OTHER than alphanumeric sequence ( i.e. in descending order by expected frequency ), and doing a sequential search.

And, if the argument is numeric ( e.g. AGE ), and not overly large ( e.g. not a number with a max of 9,999,999 ), the fastest search of all is a direct use of the argument value as a table subscript/index.
_________________
A computer once beat me at chess, but it was no match for me at kick boxing.
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Thu Apr 15, 2010 1:59 am    Post subject: Reply with quote

there is a point where the binary search will use less machine time than the serial search.

a binary search only out-performs in the sense that there are less comparisions.

both do an increment of displacement
both do a compare (for end of search)
both do a compare of the item.

but binary search has to continually:
  • maintain the current high and low item
  • do a divide of existing range based on the high and low
  • calculate the displacement


i have seen literature in the 80's that suggested 50 totals items, and other that suggested 126 (128?)
which is the break even point where the binary search is actually faster.

I will find a link to document that has based my understanding.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
haatvedt
Beginner


Joined: 14 Nov 2003
Posts: 66
Topics: 0
Location: St Cloud, Minnesota USA

PostPosted: Sat Apr 17, 2010 1:03 pm    Post subject: Reply with quote

I had a situation where we loaded a large VSAM file into memory to be searched by online CICS application. We encountered problems trying to emulate the VSAM START verb using COBOL SEARCH ALL verb when the key does not exist in the array. To get around this we had to write our own BINARY SEARCH in COBOL.

The array which we are searching contains about 240,000 entries.

We found that the hand coded BINARY SEARCH was significantly more efficient in terms of cpu usage than the COBOL "SEARCH ALL" verb.

The code was modeled after KNUTH's binary search, see this link

http://www.z390.org/contest/p21/P21DW1.TXT

the key to maximizing the performance of the code below was to use PIC S9(8) COMP for all the binary fields. This avoids the check for binary overflow in the generated code. Also we used the compiler option TRUNC(OPT) to avoid the code generated to check for truncation.

Note --> the IF statement after the PERFORM loop is to check for a "not found" condition. To emulate the VSAM START command we need to position the INDEX to the first row which is >= the search key.

Code:

      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
      *                                                               *
      *    NOTICE THAT BECAUSE WE DO SEARCHES FOR KEYS WHICH ARE      *
      *    NOT PRESENT IN THE CACHE, WE HAVE TO USE OUR OWN HAND      *
      *    CODED BINARY SEARCH. THE REASON FOR THIS IS THAT THE       *
      *    SEARCH ALL VERB DOES NOT SET THE INDEX AFTER A NOT         *
      *    FOUND CONDITION TO POINT TO THE LAST ROW IT CHECKED.       *
      *                                                               *
      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

           MOVE +1                     TO BIN-LOW.
           MOVE BCNTR-TCA1-ENTRIES-USED
                                       TO BIN-HIGH.

           PERFORM WITH TEST AFTER
               UNTIL BIN-LOW > BIN-HIGH
               COMPUTE BIN-RANGE = BIN-HIGH - BIN-LOW
               COMPUTE BIN-MID = (BIN-RANGE / 2) + BIN-LOW
               SET TCA1-INDEX          TO BIN-MID
               EVALUATE TRUE
                   WHEN TCA1-KEY (TCA1-INDEX) = SRCH-TCA1-KEY
                       MOVE 1          TO BIN-RANGE
                       COMPUTE BIN-LOW = BIN-HIGH + 1
                   WHEN TCA1-KEY (TCA1-INDEX) < SRCH-TCA1-KEY
                       COMPUTE BIN-LOW  = BIN-MID + 1
                   WHEN OTHER
                       COMPUTE BIN-HIGH  = BIN-MID - 1
               END-EVALUATE
           END-PERFORM.


           IF TCA1-KEY (TCA1-INDEX) < SRCH-TCA1-KEY
               SET TCA1-INDEX          UP BY +1
           END-IF.

_________________
Chuck Haatvedt

email --> clastnameatcharterdotnet

(replace lastname, at, dot with appropriate
characters)
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Mon Apr 19, 2010 6:51 am    Post subject: Reply with quote

as a follow-up to this discussion.

disregard my reference to 126 - I can not support this figure.
though thru observation over the last few decades,
i usually find that if there are less than 50 items,
I do a perform varying,
more than 50 items, I do a binary search.

as far as psmadhusudhan problem.
I understand the need to have a potential 100 item-table.
but it should always be ODO.
as even the book says,
with less than 4 items a binary search is not the best.

to force a binary search on a 100 item fixed length table
when there are only actually 3 active items,
IMUO,
is not among the best coding practices.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
Terry_Heinze
Supermod


Joined: 31 May 2004
Posts: 391
Topics: 4
Location: Richfield, MN, USA

PostPosted: Tue Apr 27, 2010 2:08 pm    Post subject: Reply with quote

Although I realize that there is a trade off point at which a binary search will/will not outperform a serial search, I've often coded a binary search regardless of the current number of occurrences knowing that 9 times out of 10, the table size will eventually exceed that trade off value. And I almost always use the ODO clause since the table size I've loaded are usually not known until execute time.
_________________
....Terry
Back to top
View user's profile Send private message Send e-mail
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