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 statement in Sapscript

Former Member
0 Likes
4,314

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
Read only

Former Member
0 Likes
2,437

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
Read only

Former Member
0 Likes
2,438

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.

Read only

0 Likes
2,437

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

Read only

0 Likes
2,437

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

Read only

0 Likes
2,437

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.

Read only

0 Likes
2,437

Thanks Vijay and Hymavathi,

removing braces solved my problem.

regards

Nishant

Ps: i have awarded points to helpful ansers.

Read only

Former Member
0 Likes
2,437

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

Read only

0 Likes
2,437

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

Read only

0 Likes
2,437

Hi Santosh,

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

Regards

Nishant

Read only

Simha_
Product and Topic Expert
Product and Topic Expert
0 Likes
2,437

Hi ,

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

It may help u..

Cheers,

Simha.

Read only

Former Member
0 Likes
2,437

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

Read only

hymavathi_oruganti
Active Contributor
0 Likes
2,437

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

Read only

Former Member
0 Likes
2,437

hi

how about calling perform in ur script

and put all ur conditions there itself..

thanksss........

Read only

Former Member
0 Likes
2,437

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