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

Order of evaluation


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

New User


Joined: 12 Feb 2007
Posts: 13
Location: chennai

PostPosted: Fri Feb 08, 2008 12:53 pm
Reply with quote

Hi,

I have a condition expression as below

MOVE SPACES TO WS-OUTPUT
IF (WS-FLAG1 = "D"
AND WS-FLAG2 = "B" OR "D")
OR (WS-FLAG1 = "W"
AND WS-FLAG2 = "B" OR "W")
MOVE WS-FLAG1 TO WS-OUTPUT
END-IF.

The value of WS-FLAG1 value is B and WS-FLAG2 value is W. The WS-OUTPUT is set to B. Can anyone explain me how the evaluation is happening.
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Fri Feb 08, 2008 1:03 pm
Reply with quote

Programming basics- AND is evaluated before OR. Does it ring any bells in your head? icon_smile.gif
Back to top
View user's profile Send private message
Rehana

New User


Joined: 12 Feb 2007
Posts: 13
Location: chennai

PostPosted: Fri Feb 08, 2008 1:06 pm
Reply with quote

Hi agkshirsagar

Thanks for that tip, but if you can explain me in detail the order of evaluation.

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

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Fri Feb 08, 2008 1:16 pm
Reply with quote

Code:

IF (WS-FLAG1 = "D"
AND WS-FLAG2 = "B" OR "D")
OR (WS-FLAG1 = "W"
AND WS-FLAG2 = "B" OR "W")

This can be visualised as-
IF ( condition1 OR condition2) OR ( condition3 OR condition4)
Order of precedence is -
( - parentheses , AND , OR

so first ()
condition1 WS-FLAG1 = "D" AND WS-FLAG2 = "B" = false
condition2 "D" = true
FALSE OR TRUE = TRUE

TRUE OR Second () = True
Second bracket can be evaluated using similar thechnique.

These kind of confusing conditions can be avoided by using parentheses at proper places.

For example:

Code:

IF (WS-FLAG1 = "D"
AND (WS-FLAG2 = "B" OR "D"))
OR (WS-FLAG1 = "W"
AND (WS-FLAG2 = "B" OR "W"))
Back to top
View user's profile Send private message
Rehana

New User


Joined: 12 Feb 2007
Posts: 13
Location: chennai

PostPosted: Fri Feb 08, 2008 1:56 pm
Reply with quote

Hi,

Thanks for the mail. But i didn't quite understand

condition2 "D" = true

How did you arrive at this. I thought

(WS-FLAG1 = "D" AND WS-FLAG2 = "B" OR "D")

will be
(WS-FLAG1 = "D" AND WS-FLAG2= "B" OR WS-FLAG1 = "D" AND WS-FLAG2 = "D")

which will evaluate to False as WS-FLAG1 value is B and WS-FLAG2 value is W. Please elaborate
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Fri Feb 08, 2008 6:30 pm
Reply with quote

(WS-FLAG1 = "D" AND WS-FLAG2 = "B" OR "D")

will actually be this

(WS-FLAG1 = "D" AND WS-FLAG2 = "B" OR WS-FLAG2 = "D")

not what you thought it will be. You need to use the (()) correctly as agkshirsagar showed in his code block like this

Code:

IF (WS-FLAG1 = "D" AND (WS-FLAG2 = "B" OR "D"))
OR (WS-FLAG1 = "W"AND (WS-FLAG2 = "B" OR "W"))
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Mon Feb 11, 2008 3:26 pm
Reply with quote

I apologise for the mistake I did in my last post (And that confused rehana even more) icon_redface.gif icon_redface.gif icon_redface.gif
I thought it was very very simple question and went on to give answer in hurry.
It should be-
condition1 WS-FLAG1 = "D" AND WS-FLAG2 = "B" = false
condition2 "D" = False ( "D" means WS-FLAG2 = "D" )

first () = false

condition3 WS-FLAG1 = "W"AND WS-FLAG2 = "B" = False
condition4 "W" - True ( as WS-FLAG2 = "W")
second () = true

False OR True = True
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 Rotate partition-logical & physic... DB2 0
No new posts DB2 Load - Sort Or order BY DB2 1
No new posts GDG all in sequence order JCL & VSAM 9
No new posts Combining more 4 files with sorted or... DFSORT/ICETOOL 3
No new posts how to show listing in physical locat... PL/I & Assembler 2
Search our Forums:

Back to Top