View previous topic :: View next topic
|
Author |
Message |
Rehana
New User
Joined: 12 Feb 2007 Posts: 13 Location: chennai
|
|
|
|
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 |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
Programming basics- AND is evaluated before OR. Does it ring any bells in your head? |
|
Back to top |
|
|
Rehana
New User
Joined: 12 Feb 2007 Posts: 13 Location: chennai
|
|
|
|
Hi agkshirsagar
Thanks for that tip, but if you can explain me in detail the order of evaluation.
Regards, |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
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 |
|
|
Rehana
New User
Joined: 12 Feb 2007 Posts: 13 Location: chennai
|
|
|
|
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 |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 632 Location: Wisconsin
|
|
|
|
(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 |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
I apologise for the mistake I did in my last post (And that confused rehana even more)
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 |
|
|
|