Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Query on When clause in search statement

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Query on When clause in search statement
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    Post subject:
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    Post subject:
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    Post subject: Hi
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    Post subject:
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    Post subject:
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    Post subject: Hi
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Omegamon for DB2 query ashek15 DB2 0 Wed Feb 15, 2017 11:25 am
No new posts Query on DB2 WLM stored procedures ashek15 DB2 8 Sun Feb 12, 2017 11:13 pm
No new posts ROUNDED Problem with COMPUTE statement shalem COBOL Programming 11 Thu Feb 09, 2017 8:16 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us