Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

help required in IF statement

Former Member
0 Likes
1,977

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,339

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

8 REPLIES 8
Read only

Former Member
0 Likes
1,340

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

Read only

Former Member
0 Likes
1,339

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

Read only

Former Member
0 Likes
1,339

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

Read only

Former Member
0 Likes
1,339

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

Read only

Former Member
0 Likes
1,339

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

Read only

Former Member
0 Likes
1,339

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

Read only

Former Member
0 Likes
1,339

hi Preeti.

Close this thread, if you find the answers relevent.

Regards,

Richa

Read only

0 Likes
1,339

Hi Guys

Thanks