2006 Aug 31 2:33 PM
Hi all,
I don't have any programming background
But now i need to look at this
P = 11.
if not ( p eq 10 or p eq 11 or p eq 12 ) .
clear p.
else.
write : / p.
endif.
Here the control goes to else part.
output p =11
P = 11.
if ( p ne 10 or p ne 11 or p ne 12 ) .
clear p.
else.
write : / p.
endif.
Here control goes and clears p.
Can anyone give me a clear idea as how this statements are working.I thought they would give the same results,but its not
Thanks
Preeti
2006 Aug 31 2:40 PM
hi Preeti,
or statement works like if any one of the condition is true, it is true.
example :
(cond1 or cond2 or cond3 or cond4...)
if any one of these conditions cond1, cond2, cond3... is true, the result is true.
so in first case.
P = 11.
if not ( p eq 10 or <b>p eq 11</b> or p eq 12 ) .
clear p.
else.
write : / p.
endif.p eq 11 is true -> so the result of whole statement in () is true -> then not(true)->not of true is false, so the result of this statement is false.
So it goes to else part and writes p.
in Second case.
P = 11.
if ( <b>p ne 10</b> or p ne 11 or p ne 12 ) .
clear p.
else.
write : / p.
endif.p ne 10 is true -> so the result of whole statement in () is true ->, So it goes to if part and clears p.
Hope this clears your doubt.
Regards,
Richa
hi Preeti,
or statement works like if any one of the condition is true, it is true.
example :
(cond1 or cond2 or cond3 or cond4...)
if any one of these conditions cond1, cond2, cond3... is true, the result is true.
so in first case.
P = 11.
if not ( p eq 10 or <b>p eq 11</b> or p eq 12 ) .
clear p.
else.
write : / p.
endif.p eq 11 is true -> so the result of whole statement in () is true -> then not(true)->not of true is false, so the result of this statement is false.
So it goes to else part and writes p.
in Second case.
P = 11.
if ( <b>p ne 10</b> or p ne 11 or p ne 12 ) .
clear p.
else.
write : / p.
endif.p ne 10 is true -> so the result of whole statement in () is true ->, So it goes to if part and clears p.
Hope this clears your doubt.
Regards,
Richa
2006 Aug 31 2:40 PM
hi Preeti,
or statement works like if any one of the condition is true, it is true.
example :
(cond1 or cond2 or cond3 or cond4...)
if any one of these conditions cond1, cond2, cond3... is true, the result is true.
so in first case.
P = 11.
if not ( p eq 10 or <b>p eq 11</b> or p eq 12 ) .
clear p.
else.
write : / p.
endif.p eq 11 is true -> so the result of whole statement in () is true -> then not(true)->not of true is false, so the result of this statement is false.
So it goes to else part and writes p.
in Second case.
P = 11.
if ( <b>p ne 10</b> or p ne 11 or p ne 12 ) .
clear p.
else.
write : / p.
endif.p ne 10 is true -> so the result of whole statement in () is true ->, So it goes to if part and clears p.
Hope this clears your doubt.
Regards,
Richa
2006 Aug 31 2:40 PM
Hi,
Lets go back to basics of boolean algebra.
Your first case.
Compl ( A or B or C )
(A or B or C) is equal to (A and ~B and ~C ).
that means your first statement gets converted to
IF ( P NE 10 AND P NE 11 AND P NE 12 ).
ELSE.
ENDIF.
Whereas your second statement.
if ( p ne 10 or p ne 11 or p ne 12 ) .
Here if P = 11, what happens is SAP will find that first condition is getting satisfied i.e P NE 10 and rest of the conditions are OR, so it will immediately assume it is not true.
But in first conditon.
IF ( P NE 10 AND P NE 11 AND P NE 12 ).
Since it is AND condition, SAP will check all three conditions and find that second part P NE 11 is satisfying the critirea.
Hope u got the picture
2006 Aug 31 2:42 PM
Hi
The condition "p ne 10 or p ne 11 or p ne 12" is always true, infact
if p = 11, it's true p = 10 and p = 12.
If you want to control a variable is different to certain values in the same time you have to use AND and not OR:
if ( p ne 10 and p ne 11 and p ne 12 ) .
clear p.
else.
write : / p.
endif.
Max
2006 Aug 31 2:45 PM
both the outputs are correct ,
In the first statement control will goto else part only bcoz in th brackets one of ur statements is true and not of that is false , so it will goto else
in ur second statement control will goto p ne 10 first , as this is true , it will clear , to correct that do like this
Message was edited by: Chandrasekhar Jagarlamudi
2006 Aug 31 3:08 PM
hi
good
in the first if statement you r checking the eq and in the second if statement you r checking ne, so it is clearing the P.
you can check this by putting the breakpoint.
thanks
mrutyun
2006 Aug 31 3:17 PM
Hi preeti,
first let us know about OR logic,
<b>if any of the condition(or expression) is true then o/p is true else false.</b>
<b>In the 1st case</b>
first the condition in (...) is evaluated against value of p given (i.e. 11).
since all the conds are true the o/p is true
next <b>if not( ) means</b> negation of the value obtained
if the o/p obtained is true then it becomes false
hence goes to else part and vice versa.
<b>In the 2nd case,</b>
again the condition in (...) is evaluated
since it is checking for not equal to and as 2 conds are true, the o/p is true,hence goes to if part and clears the variable.
Regards,
Sowjanya
2006 Aug 31 4:19 PM
hi Preeti.
Close this thread, if you find the answers relevent.
Regards,
Richa
2006 Aug 31 8:29 PM
| User | Count |
|---|---|
| 5 | |
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |