Application Development 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: 

IF statement in Sapscript

Former Member
0 Kudos

Hi Guys,

I am using IF statements in my sapscript , but am getting an error -- "AND, OR or end of condition expected" . I have pasted my code below. Any suggestions in this regard would be helpful.

/: IF ( &BSEG-BELNR& EQ &BKPF-BELNR& )

/: IF ( &BSEG-KOART& = 'D' )

/: IF ( &BKPF-BLART& = 'KR' )

M3 ,,&BKPF-BELNR&,,&BKPF-XBLNR&,,&BKPF-BLDAT&,,&BSEG-SGTXT(25)&

= ,,&BSEG-DMBTR&,,&BKPF-HWAER&

/: IF STRLEN(&BSEG-SGTXT&) GT 25

M3 ,,,,,,,,&BSEG-SGTXT+25&

/: ENDIF

/: PERFORM CAL_TOTAL IN PROGRAM ZFR_PYTADV1

/: USING &BSEG-DMBTR&

/: CHANGING &W_TOTAL&

/: ENDPERFORM

/: ELSEIF ( &BKPF-BLART& = 'RE' )

M3 ,,&BKPF-BELNR&,,&BKPF-XBLNR&,,&BKPF-BLDAT&,,&BSEG-SGTXT(25)&

= ,,&BSEG-DMBTR&,,&BKPF-HWAER&

/: IF STRLEN( &BSEG-SGTXT& ) GT 25

M3 ,,,,,,,,&BSEG-SGTXT+25&

/: ENDIF

/: PERFORM CAL_TOTAL IN PROGRAM ZFR_PYTADV1

/: USING &BSEG-DMBTR&

/: CHANGING &W_TOTAL&

/: ENDPERFORM

/: ENDIF

/: ENDIF

/: ENDIF

regards

Nishant

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi nishant,

u have to write

/: IF ( &BSEG-BELNR& EQ &BKPF-BELNR& )

or ( &BSEG-KOART& = 'D' )

or ( &BKPF-BLART& = 'KR' ).

-


-


/: endif.

hope this helps,

priya.

13 REPLIES 13

Former Member
0 Kudos

hi nishant,

u have to write

/: IF ( &BSEG-BELNR& EQ &BKPF-BELNR& )

or ( &BSEG-KOART& = 'D' )

or ( &BKPF-BLART& = 'KR' ).

-


-


/: endif.

hope this helps,

priya.

0 Kudos

Hi Priya,

I want both the first and second IF statements to be fulfilled before control goes on to 3rd IF statement.

I tried using AND statements i:e:

IF ( &BSEG-BELNR& EQ &BKPF-BELNR& ) AND

( &BSEG-KOART& = 'D' )

But its not working...

Regards

Nishant

0 Kudos

Hi Nishant,

it is because of <b>Brackets</b> it is giving that error.you should have to write the separate code inorder to avoid the Brackets.

i did it at my end.

it is not giving any errors..

/:    IF  A = 10 .      
/:   IF  A  = 'D' .     
/:   IF A = 'KR' .      
/:                      
/:    IF A GT 25.       
/:    ENDIF             
/:   ELSEIF A = 2       
          
/:    IF A GT 25.       
/:    ENDIF.            
/:   ENDIF.             
/:   ENDIF.             
/:   ENDIF 

Regards

vijay

0 Kudos

hi nishant,

try

/: IF ( &BSEG-BELNR& EQ &BKPF-BELNR& )

and ( &BSEG-KOART& = 'D' )

and ( &BKPF-BLART& = 'KR' )

M3 ,,&BKPF-BELNR&,,&BKPF-XBLNR&,,&BKPF-BLDAT&,,&BSEG-SGTXT(25)&

= ,,&BSEG-DMBTR&,,&BKPF-HWAER&

/: ENDIF.

/: IF STRLEN(&BSEG-SGTXT&) GT 25

M3 ,,,,,,,,&BSEG-SGTXT+25&

/: ENDIF

HOPE THIS HELPS,

PRIYA.

0 Kudos

Thanks Vijay and Hymavathi,

removing braces solved my problem.

regards

Nishant

Ps: i have awarded points to helpful ansers.

former_member181962
Active Contributor
0 Kudos

HI NIshant,

I thinkk you are missing a period at the end of each if statement. Try putting a '.' at the end of each statement.

Regards,

Ravi

0 Kudos

Period Missing at the end of If Statement and in most of the places of your code. Remove <b>BRACES</b>

0 Kudos

Hi Santosh,

I tried placing periods at the end of IF statements. I dont think periods are required in Sapscripts.

Regards

Nishant

Simha_
Employee
Employee
0 Kudos

Hi ,

Use <b>OR</b> condition in between ur if statements...

It may help u..

Cheers,

Simha.

former_member181962
Active Contributor
0 Kudos

try changing this statement with paranthesis:

/: IF ( STRLEN( &BSEG-SGTXT& ) GT 25 )

By the way, are you sure you can use the strlen function in sap script directly?

Instead caluculate the strlen in the driver program itself and use that variable in the script.

Regards,

Ravi

hymavathi_oruganti
Active Contributor
0 Kudos

periods are not required in scripts

as u r not using and or OR and they are separate if stetements,

just remove the braces ( ) in every expression and try

Former Member
0 Kudos

hi

how about calling perform in ur script

and put all ur conditions there itself..

thanksss........

Former Member
0 Kudos

Hi Nishant,

u cannot use simultaneous IF conditions in sapscritp...u need to use AND ...dunno y ur command using AND is not working..just try out a few things like debugging the script n checking the values that these variables are getting at runtime so that u get to know wat exactly the problem is..

Regards

Bikash