Page 1 of 1

SEARCH AND SEARCH ALL

PostPosted: Thu Sep 26, 2013 3:01 pm
by sinmani
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

Re: SEARCH AND SEARCH ALL

PostPosted: Thu Sep 26, 2013 3:08 pm
by Robert Sample
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.

Re: SEARCH AND SEARCH ALL

PostPosted: Thu Sep 26, 2013 3:55 pm
by BillyBoyo
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.

Re: SEARCH AND SEARCH ALL

PostPosted: Thu Sep 26, 2013 6:19 pm
by Robert Sample
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.

Re: SEARCH AND SEARCH ALL

PostPosted: Thu Sep 26, 2013 9:37 pm
by sinmani
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.

Re: SEARCH AND SEARCH ALL

PostPosted: Thu Sep 26, 2013 9:44 pm
by sinmani
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

Re: SEARCH AND SEARCH ALL

PostPosted: Thu Sep 26, 2013 10:20 pm
by dick scherrer
Hello,

If you move at the group level, the entire table will be initialized.
No need for the loop.

Re: SEARCH AND SEARCH ALL

PostPosted: Thu Sep 26, 2013 11:02 pm
by chaat
another consideration is that you have unique keys, the SEARCH ALL verb does not handle searches against arrays which have duplicate keys.

Re: SEARCH AND SEARCH ALL

PostPosted: Fri Sep 27, 2013 2:15 am
by BillyBoyo
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?