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

Multiple checks in a WHEN clause


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Kamlesh Kamal

New User


Joined: 16 May 2008
Posts: 36
Location: Kolkata,India

PostPosted: Mon Sep 28, 2009 8:56 pm
Reply with quote

Hi,

Can anyone confirm if this WHEN clause will work?

Code:
EVALUATE TRUE                                   
WHEN ((POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'FYGB' OR
     POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'FYNB'  OR
     POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'RENB'  OR
     POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'RENN'  OR
     POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'MAVG'  OR
     POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'MLGA'  OR
     POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'MGAN'  OR
     POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'NPMF') OR
     (SPEC-PSTN-CD  OF DCLTCSEPIPRDCR(1:2)       
     NOT EQUAL TO '72' AND                       
     (POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'MAVF' OR
      POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'MAVR' OR
      POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'MGAF' OR
      POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'MGAR' OR
      POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'MLGF' OR
      POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'MLGR' OR
      POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'RNBF' OR
      POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'RNBR' OR
      POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'RNNF' OR
      POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'RNNR')))


I guess my requirement is clear from the where clause but the conditions of

Code:
(SPEC-PSTN-CD  OF DCLTCSEPIPRDCR(1:2)     
NOT EQUAL TO '72' AND                     
(POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'MAVF' OR
 POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'MAVR' OR
 POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'MGAF' OR
 POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'MGAR' OR
 POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'MLGF' OR
 POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'MLGR' OR
 POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'RNBF' OR
 POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'RNBR' OR
 POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'RNNF' OR
 POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'RNNR')))

are getting skipped---not checked..
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Sep 28, 2009 9:12 pm
Reply with quote

Hello,

What happens if the code only checks for NOT EQUAL TO '72'? Does this evaluate true?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Mon Sep 28, 2009 9:23 pm
Reply with quote

Quote:
Can anyone confirm if this WHEN clause will work?
Of course it will -- it may not give you the result you want, but it will evaluate and produce a result.

You need to review chapter 6.1.6 of the COBOL Language Reference manual to determine exactly what you want to do. For example, as you have it coded, if POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'FYGB' is true, none of the following conditions will be checked -- which is due to the way COBOL evaluates conditions as described in chapter 6.1.6. When evaluating OR conditions, either side being true forces the entire condition to be true and evaluation ends at that point.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Sep 28, 2009 9:27 pm
Reply with quote

Hi Robert - welcome "back" icon_smile.gif

d
Back to top
View user's profile Send private message
Kamlesh Kamal

New User


Joined: 16 May 2008
Posts: 36
Location: Kolkata,India

PostPosted: Mon Sep 28, 2009 9:32 pm
Reply with quote

Hi,

Got your point..Now I have divided my logic in two separate parts.

Code:
EVALUATE TRUE                                       
WHEN (POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'FYGB' OR   
     POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'FYNB'  OR   
     POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'RENB'  OR   
     POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'RENN'  OR   
     POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'MAVG'  OR   
     POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'MLGA'  OR   
     POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'MGAN'  OR   
     POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'NPMF')       
                                                   
   MOVE ERN-AMT             OF DCLTCMPRDCR-ERN-DTL 
                            TO WS-STI-COMM-CALC-AMT1
                               WS-ERN-AMT-OUTPUT   


AND

Code:
WHEN (SPEC-PSTN-CD  OF DCLTCSEPIPRDCR(1:2)         
     NOT EQUAL TO '72' AND                         
     (POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'MAVF' OR   
      POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'MAVR' OR   
      POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'MGAF' OR   
      POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'MGAR' OR   
      POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'MLGF' OR   
      POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'MLGR' OR   
      POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'RNBF' OR   
      POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'RNBR' OR   
      POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'RNNF' OR   
      POOL-CD OF DCLTCMPRDCR-ERN-DTL = 'RNNR'))     
                                                   
   MOVE ERN-AMT             OF DCLTCMPRDCR-ERN-DTL 
                            TO WS-STI-COMM-CALC-AMT1
                               WS-ERN-AMT-OUTPUT   


Still the checks for the conditions in second WHEN clause is not working..

Do I use IS NOT EQUAL TO instaed of NOT EQUAL TO?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Sep 28, 2009 9:43 pm
Reply with quote

Why don't you get rid of that dumb NOT and:
Code:

EVALUATE  TRUE
    WHEN  THINGAMEBOB(WITH REFERENCE MODIFICATION) = '72'
          CONTINUE
    WHEN  <all the other mess without the NOT>
          PERFORM DO-WHAT-YOU-WANT
END-EVALUATE
Back to top
View user's profile Send private message
Kamlesh Kamal

New User


Joined: 16 May 2008
Posts: 36
Location: Kolkata,India

PostPosted: Mon Sep 28, 2009 10:20 pm
Reply with quote

That can't be done I guess as I have to check for both the condition NOT EQUAL TO 72 AND the other ORs that I have..
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Mon Sep 28, 2009 11:05 pm
Reply with quote

Thanks, Dick -- it was a nice vacation (although it rained every port, at least the ship was enjoyable).

Kamlesh, changing NOT EQUAL TO to IS NOT EQUAL TO is not going to change the COBOL results -- the two phrases are considered the same by COBOL. As you now have it coded, if the first two bytes of SPEC-PSTN-CD OF DCLTCSEPIPRDCR are equal to '72' then the condition evaluates to false and the rest of the condition will not be evaluated as per COBOL rules cited above. So have you verified that you have data records with something other than '72' in the first two bytes of SPEC-PSTN-CD OF DCLTCSEPIPRDCR?

The rule of thumb is that COBOL evaluates only as much as it has to; if a partial evaluation of a complex OR condition comes up TRUE, then the expression is going to be TRUE and COBOL stops evaluating at that point; similarly, if a partial evaluation of a complex AND condition comes up FALSE, then the expression is going to be FALSE and COBOL stops evaluating at that point.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Sep 29, 2009 12:29 am
Reply with quote

Hello,

Quote:
Still the checks for the conditions in second WHEN clause is not working..
As i suggested earlier, try a test using only the test for '72' in the second WHEN - forget the others. If the test for 72 alone fails, that is the problem. . .
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Tue Sep 29, 2009 1:09 am
Reply with quote

In addition to the other suggestions, I would add that your EVALUATE is so wordy that it is difficult for many to understand. One option is to move POOL-CD OF DCLTCMPRDCR-ERN-DTL and SPEC-PSTN-CD OF DCLTCSEPIPRDCR(1:2) to field names and reference them by using condition names (88 levels).
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 INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Grouping by multiple headers DFSORT/ICETOOL 7
No new posts How to append a PS file into multiple... JCL & VSAM 3
Search our Forums:

Back to Top