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

IF Condition in SAPscript

aris_hidalgo
Contributor
0 Likes
7,742

Hello experts,

I am currently having trouble inserting my IF statement in the main window of a form. what I want to do is

IF mseg-bwart is NOT equal to '631' then it would do the code below. if it is EQUAL to 631, then it would not do the code below. I have tried using nested if but it always fails. Any help would be appreciated. Many thanks guys and take care!

/: IF &MKPF-TCODE2& NE 'MB01' AND &MKPF-TCODE2& NE 'MIGO_GR'

I1 ,,&MSEG-WEMPF&

/: ELSE

I1 ,,&MSEG-EBELN&

/: ENDIF

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,705

Hi Viray,

try using Case..

sorry for the previous one..

/: CASE &MSEG-BWART& 
 /: WHEN '631'.
 /: WHEN OTHERS. 
 / : IF &MKPF-TCODE2& NE 'MB01' AND &MKPF-TCODE2&  NE 'MIGO_GR'I1 ,,&MSEG-WEMPF&
/: ELSE
I1 ,,&MSEG-EBELN&
/: ENDIF 
 /: ENDCASE

regards

satesh

Message was edited by: Satesh R

Message was edited by: Satesh R

9 REPLIES 9
Read only

Former Member
0 Likes
3,705

Hi,

please send the code where it is not working.

So that we can help u out in this regard.this code is not suffient.

Regards,

Sreevani

Read only

0 Likes
3,705
/: IF &MSEG-BWART& NE '631' AND &MKPF-TCODE2& NE 'MB01' AND &MKPF-TCODE2& NE 'MIGO_GR'
I1 ,,&MSEG-WEMPF&
/: ELSEIF &MSEG-BWART& NE '631' 
I1 ,,&MSEG-EBELN&
/: ENDIF
Read only

Former Member
0 Likes
3,705

1ST CHECK THAT IN DRIVER PROGRAM ALL THE VALUE OF MSEG TABLE IS FETCH...

IN DRIVER PROGRAM...

SEELCT * FROM MSEG WHERE CONDN.

/:IF &MSEG-BWART& = '631'

DO THIS

:ELSE

DO THIS

:ENDIF

Message was edited by: kishan negi

Read only

Former Member
0 Likes
3,706

Hi Viray,

try using Case..

sorry for the previous one..

/: CASE &MSEG-BWART& 
 /: WHEN '631'.
 /: WHEN OTHERS. 
 / : IF &MKPF-TCODE2& NE 'MB01' AND &MKPF-TCODE2&  NE 'MIGO_GR'I1 ,,&MSEG-WEMPF&
/: ELSE
I1 ,,&MSEG-EBELN&
/: ENDIF 
 /: ENDCASE

regards

satesh

Message was edited by: Satesh R

Message was edited by: Satesh R

Read only

Former Member
0 Likes
3,705

try doing this.

    • IF mseg-bwart is NOT equal to '631' then it would do the code below. if it is EQUAL to 631, then it would not do the code below

/: IF &mseg-bwart& NE 631 .

/: IF &MKPF-TCODE2& NE 'MB01' AND &MKPF-TCODE2& NE 'MIGO_GR'

I1 ,,&MSEG-WEMPF&

/: ELSE

I1 ,,&MSEG-EBELN&

/: ENDIF

/:ENDIF

What i want to say that sometime i had observe if you give the neagtive condition along with AND and all , it behaves very differently , i would advices you to break your IF with a single condition followed by other and try to see the results.

I think that will wrk.

Cheers

Sunny

Rewrd points, if found helpful

Read only

Former Member
0 Likes
3,705

Hello Viraylab,

First and foremost is all the variables that u are using should be available in sapscript. If they are then u can us the following..

/: CASE &MSEG-BWART&

/: WHEN '631'.

/: IF &MKPF-TCODE2& NE 'MB01' AND &MKPF-TCODE2&

NE 'MIGO_GR'

I1 ,,&MSEG-WEMPF&

/: ELSE

I1 ,,&MSEG-EBELN&

/: ENDIF

/: WHEN OTHERS

/: ENDCASE

Try using debugger to find out exact reason if it is still skipping the code.

Read only

Former Member
0 Likes
3,705

I don't think you can use nested IFs in SAPScript.

You may have to repeat some of the code and use a bigger IF statement to include all the conditions.

Read only

0 Likes
3,705

hi,

this is always a problem in scripts,

the best way is to set a flag inside the code.and use that flag here that is the best way.

regards,

Sasi

Read only

0 Likes
3,705

try to use this

/: IF &MSEG-BWART& NE '631' AND &MKPF-TCODE2& NE 'MB01' AND &MKPF-TCODE2& NE 'MIGO_GR'

I1 ,,&MSEG-WEMPF&/:

ELSE

I1 ,,&MSEG-EBELN&/: ENDIF

endif