SEARCH AND SEARCH ALL



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

SEARCH AND SEARCH ALL

Postby sinmani » Thu Sep 26, 2013 3:01 pm

Hi Forum,

I have come across a strange behavior in my code. Where in I was using SEARCH ALL to search my table which an was not working.
On the other hand when I used SEARCH then it worked just fine.
Here is my table definition.
Can anyone tell me why SEARCH worked while SEARCH ALL didn't??

01 WS-WALL-TABLE.
05 WS-WALL-TBL OCCURS 100 TIMES
ASCENDING KEY IS WS-DC-CODE
WS-WALL-IND
INDEXED BY TBL-INDEX2.
10 WS-DC-CODE PIC X(04).
10 WS-WALL-IND PIC X(01).


SET TBL-INDEX2 TO 1
MOVE 'N' TO FLAG
MOVE EHDS-INPUT-DC-NO TO OL-DC-NO.

SEARCH WS-WALL-TBL
AT END MOVE 'N' TO FLAG
WHEN WS-DC-CODE (TBL-INDEX2) = DC-NO
AND WS-WALL-IND (TBL-INDEX2) = 'Y'
MOVE 'Y' TO FLAG
END-SEARCH
-----------------------------------------
As long as you think you are a student, you are doing well.
The day you consider yourself as the master of the game..........well
sinmani
 
Posts: 93
Joined: Thu Mar 22, 2012 10:02 am
Has thanked: 14 times
Been thanked: 0 time

Re: SEARCH AND SEARCH ALL

Postby Robert Sample » Thu Sep 26, 2013 3:08 pm

Did you ensure that the table was loaded by ascending key value? Merely specifying "ASCENDING KEY" will NOT order the table elements -- YOU must do that when you load the table. And if the table is not ordered by the key value, a SEARCH ALL is going to produce unpredictable results.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: SEARCH AND SEARCH ALL

Postby BillyBoyo » Thu Sep 26, 2013 3:55 pm

Also,he presence of the AND implies multiple (more than one) equal values of WS-DC-CODE. SEARCH ALL cannot process multiple values for the same key.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: SEARCH AND SEARCH ALL

Postby Robert Sample » Thu Sep 26, 2013 6:19 pm

Also, if you do not have 100 defined values in your table (or the count of table entries can vary from run to run), before you start loading the table you will need
MOVE HIGH-VALUES TO WS-WALL-TABLE
if you want to use SEARCH ALL.

These users thanked the author Robert Sample for the post:
sinmani (Thu Sep 26, 2013 9:41 pm)
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: SEARCH AND SEARCH ALL

Postby sinmani » Thu Sep 26, 2013 9:37 pm

BillyBoyo wrote:Also,he presence of the AND implies multiple (more than one) equal values of WS-DC-CODE. SEARCH ALL cannot process multiple values for the same key.


Well I needed the and condition. So it was giving me compilation error that the variable is not KEY of table.
So I declared the the composite key.
I tried removing the AND condition but it was not searching the table even for a single field.
-----------------------------------------
As long as you think you are a student, you are doing well.
The day you consider yourself as the master of the game..........well
sinmani
 
Posts: 93
Joined: Thu Mar 22, 2012 10:02 am
Has thanked: 14 times
Been thanked: 0 time

Re: SEARCH AND SEARCH ALL

Postby sinmani » Thu Sep 26, 2013 9:44 pm

Robert Sample wrote:Also, if you do not have 100 defined values in your table (or the count of table entries can vary from run to run), before you start loading the table you will need
MOVE HIGH-VALUES TO WS-WALL-TABLE
if you want to use SEARCH ALL.


Yes Robert I do not have 100 values most of the times.
So I think I will have to initialize it with high values like you suggested!! Thank you.

Does MOVE high value to table initialize it in one go or do we have to run through the table in all occurrences and MOVE HIGH VALUE in each column
-----------------------------------------
As long as you think you are a student, you are doing well.
The day you consider yourself as the master of the game..........well
sinmani
 
Posts: 93
Joined: Thu Mar 22, 2012 10:02 am
Has thanked: 14 times
Been thanked: 0 time

Re: SEARCH AND SEARCH ALL

Postby dick scherrer » Thu Sep 26, 2013 10:20 pm

Hello,

If you move at the group level, the entire table will be initialized.
No need for the loop.
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: SEARCH AND SEARCH ALL

Postby chaat » Thu Sep 26, 2013 11:02 pm

another consideration is that you have unique keys, the SEARCH ALL verb does not handle searches against arrays which have duplicate keys.
chaat
 
Posts: 27
Joined: Sun Aug 16, 2009 11:07 pm
Location: St. Cloud, Minnesota
Has thanked: 0 time
Been thanked: 1 time

Re: SEARCH AND SEARCH ALL

Postby BillyBoyo » Fri Sep 27, 2013 2:15 am

An alternative to the HIGH-VALUES is to use OCCURS DEPENDING ON for the table.

Unless you are doing many, many, SEARCH ALLs, choose the one your site is most at ease with.

However, we are tending towards thinking that you cannot use SEARCH ALL due to duplicate keys.

Perhaps you can show some sample input of the table and what you are trying to match, please?
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post