IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Query on When clause in search statement


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Rupa.P.V
Warnings : 1

New User


Joined: 04 Jul 2006
Posts: 30

PostPosted: Wed Jul 19, 2006 4:13 pm
Reply with quote

Can i use more than one condition in WHEN clause in the search statement.??

For eg:

SET CWIPCRLT-INDX TO 1.
SEARCH ALL WS-CWIPCRLT-ENTRIES
AT END MOVE 'N' TO WS-CWIPCRLT-FOUND
WHEN (WS-CWIPCRLT-NSPN(CWIPCRLT-INDX) = WS-NSPNLIST-NSPN
AND (WS-CWIPCRLT-FISCAL-YY (CWIPCRLT-INDX) =
WS-NSPNLIST-FISCAL-YY))
MOVE 'Y' TO WS-CWIPCRLT-FOUND.


If i try like above example its showing the compilation error.

Please let f me know if anyone knows how to give more than one condition in the WHEN caluse..

Thanks in advance
Please let me know
Back to top
View user's profile Send private message
giri_82

New User


Joined: 19 Jul 2006
Posts: 6

PostPosted: Wed Jul 19, 2006 4:55 pm
Reply with quote

Hi,
If we are using Search all it means a binary search.For that the Contents in the array should be in the Ascending or Descending order of the Index key defined. For accomplishing your logic

Declare WS-CWIPCRLT-NSPN and WS-CWIPCRLT-FISCAL-YY under a Group variable Say WS-CWIPCRLT-KEY. Keep WS-CWIPCRLT-KEY as the Index key while defining the Indexed array also specify the order whether Ascending or descending.

Also Declare WS-NSPNLIST-NSPN and WS-NSPNLIST-FISCAL-YY under another group variable say WS-COMP-KEY.

Now use these WS-CWIPCRLT-KEY and WS-COMP-KEY for comparison.

SEARCH ALL WS-CWIPCRLT-ENTRIES
AT END MOVE 'N' TO WS-CWIPCRLT-FOUND
WHEN WS-CWIPCRLT-KEY(CWIPCRLT-INDX) = WS-COMP-KEY
MOVE 'Y' TO WS-CWIPCRLT-FOUND

Setting Index to 1 in the beginning (SET CWIPCRLT-INDX TO 1)is not required in this case because this is a binary search.


In case I am wrong or missed any thing please correct me.

Regards,
Giri
Back to top
View user's profile Send private message
giri_82

New User


Joined: 19 Jul 2006
Posts: 6

PostPosted: Wed Jul 19, 2006 5:04 pm
Reply with quote

Hi,

What ever I mentioned above is applicable only when the array is in the order of WS-CWIPCRLT-NSPN and WS-CWIPCRLT-FISCAL-YY.Other wise we cannot use 'Search all'. Instead 'Search' can be used.The code will be like this.

SET CWIPCRLT-INDX TO 1.
SEARCH ALL WS-CWIPCRLT-ENTRIES
AT END MOVE 'N' TO WS-CWIPCRLT-FOUND
WHEN WS-CWIPCRLT-KEY(CWIPCRLT-INDX) = WS-COMP-KEY
MOVE 'Y' TO WS-CWIPCRLT-FOUND.


I think if you are using 'Search' (not 'search all') only, you can code it in the way you have mentioned also (not sure).
SET CWIPCRLT-INDX TO 1.
SEARCH WS-CWIPCRLT-ENTRIES
AT END MOVE 'N' TO WS-CWIPCRLT-FOUND
WHEN (WS-CWIPCRLT-NSPN(CWIPCRLT-INDX) = WS-NSPNLIST-NSPN
AND (WS-CWIPCRLT-FISCAL-YY (CWIPCRLT-INDX) =
WS-NSPNLIST-FISCAL-YY))
MOVE 'Y' TO WS-CWIPCRLT-FOUND.

If you are using 'Search' only , SET CWIPCRLT-INDX TO 1 is required.

Regards,
Giri
Back to top
View user's profile Send private message
Hanfur

Active User


Joined: 21 Jun 2006
Posts: 104

PostPosted: Wed Jul 19, 2006 5:25 pm
Reply with quote

Rupa,

In SEARCH ALL the WHEN condition can be of compound type formed from simple conditions but the logical connective used should only be AND.

-Han.
Back to top
View user's profile Send private message
Jerry

New User


Joined: 16 Sep 2005
Posts: 42

PostPosted: Wed Jul 19, 2006 5:39 pm
Reply with quote

Hi Rupa,

Can you please give us the exact compilation error, you are getting.
Back to top
View user's profile Send private message
Rupa.P.V
Warnings : 1

New User


Joined: 04 Jul 2006
Posts: 30

PostPosted: Wed Jul 19, 2006 5:57 pm
Reply with quote

Ya Only search without all works fine.
If i want to include more than one condition in the WHEN clause...

Thanks a lot.....
Back to top
View user's profile Send private message
Hanfur

Active User


Joined: 21 Jun 2006
Posts: 104

PostPosted: Thu Jul 20, 2006 12:44 pm
Reply with quote

Rupa,
If you use SEARCH ALL you cannot code more than one WHEN conditions ,only logical connective permitted is AND , Only Equality test allowed (>=,<= etc not allowed) and finally the array reference with index should come left in comparison as mentioned by Giri.

WHEN (WS-CWIPCRLT-NSPN(CWIPCRLT-INDX) = WS-NSPNLIST-NSPN


-Han.
Back to top
View user's profile Send private message
parikshit123

Active User


Joined: 01 Jul 2005
Posts: 269
Location: India

PostPosted: Fri Jul 21, 2006 10:53 am
Reply with quote

Hi Rupa,

You seems to be having mismatch in the paranthesis you used in WHEN clause.

Basically, you can code any valid COBOL condition in when clause.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Search two or more word with FILEAID Compuware & Other Tools 15
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
Search our Forums:

Back to Top