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
 

 

Order of evaluation

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Order of evaluation
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: 685
Location: Earth

PostPosted: Fri Feb 08, 2008 1:03 pm    Post subject:
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    Post subject: Reply to: Order of evaluation
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: 685
Location: Earth

PostPosted: Fri Feb 08, 2008 1:16 pm    Post subject:
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    Post subject: Reply to: Order of evaluation
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    Post subject:
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: 685
Location: Earth

PostPosted: Mon Feb 11, 2008 3:26 pm    Post subject:
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    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 Order BY AND Index Nileshkul DB2 2 Sat Dec 31, 2016 6:33 pm
No new posts SQL Order By related question Joseph K Thomas DB2 8 Fri Mar 18, 2016 12:53 pm
No new posts DFSORT control statements in any order ? ronald masters DFSORT/ICETOOL 2 Tue Dec 15, 2015 11:22 pm
No new posts Retrieve records in the order of alte... jacobdng Compuware & Other Tools 8 Fri Jul 31, 2015 8:16 am
No new posts Order to search CLIST if using ALTLIB... jackzhang75 CLIST & REXX 11 Thu Apr 23, 2015 8:43 pm


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