View previous topic :: View next topic
|
Author |
Message |
Rupa.P.V Warnings : 1 New User
Joined: 04 Jul 2006 Posts: 30
|
|
|
|
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 |
|
|
giri_82
New User
Joined: 19 Jul 2006 Posts: 6
|
|
|
|
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 |
|
|
giri_82
New User
Joined: 19 Jul 2006 Posts: 6
|
|
|
|
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 |
|
|
Hanfur
Active User
Joined: 21 Jun 2006 Posts: 104
|
|
|
|
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 |
|
|
Jerry
New User
Joined: 16 Sep 2005 Posts: 42
|
|
|
|
Hi Rupa,
Can you please give us the exact compilation error, you are getting. |
|
Back to top |
|
|
Rupa.P.V Warnings : 1 New User
Joined: 04 Jul 2006 Posts: 30
|
|
|
|
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 |
|
|
Hanfur
Active User
Joined: 21 Jun 2006 Posts: 104
|
|
|
|
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 |
|
|
parikshit123
Active User
Joined: 01 Jul 2005 Posts: 269 Location: India
|
|
|
|
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 |
|
|
|