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

Arithmetic opereations in sapscripts

Former Member
0 Likes
1,492

Hi: Im really fighting with sapscripts. I dont know if its possible to make arithmetic operations inside a sapscript. I've tried with the next sintaxis:

/: DEFINE &var1& = &var2& + &var3&.

and it says thas + is too long.

First of all Is possible to make arithmetic operactions in SAPSCRIPTS??????

If it's posssible, can u show me some sintaxis, cause don't find any documentation about.

Thanks

1 ACCEPTED SOLUTION
Read only

alejandro_lpez
Contributor
0 Likes
1,102

Hi,

You can send several parameters form sapscript like in a report program:

DEFINE &VSERNR(I77)& TYPE C

/: DEFINE &VSERNR2(I77)& TYPE C

/: PERFORM TOMARSERIES IN PROGRAM ZENS

/: USING &MKPF-MBLNR&

/: USING &MKPF-MJAHR&

/: USING &MSEG-MATNR&

/: USING &MSEG-ZEILE&

/: CHANGING &VSERNR&

/: CHANGING &VSERNR2&

/: ENDPERFORM

regards,

Alejandro.

9 REPLIES 9
Read only

Former Member
0 Likes
1,102

Hello,

You cannot do any arithmetic operations like adding,subtracting etc in SAP scripts.You need to do that in the print program and pass the variable into the Sapscript.

Thanks,

Kalyan

Read only

alejandro_lpez
Contributor
0 Likes
1,102

Hi,

you can create an Include program an define a Form into it. Then from sapscript invoke this form to make the atithmetic operations and return the value to sapscript.

regards,

Alejandro

Read only

Former Member
0 Likes
1,102

Hi Hund,

You cant perform arithmetic operations directly in sapscripts.

You need to perform that operations in Driver program ang get the resultant values into script. (or)

Call a subroutine from your sap script by passing parameters and define the form in driver program.

Thanks,

Vinay

Read only

Former Member
0 Likes
1,102

Thaks to all..now my problem is..

I have this sintaxis inside de SAPSCRIPT

PERFORM MODIFY IN PROGRAM ZMOD_PREC

USING &EKPO-MWSKZ& &EKPO-NETWR&

CHANGING &W_TEMP&

the program in my form starts like this:

FORM X TABLES p_input STRUCTURE ITCSY

p_input1 STRUCTURE ITCSY.

p_output STRUCTURE ITCSY.

when I execute the smartforms show me a dump that says:

the program expected 6 parameters and you have 4.

Any idea what it's wrong at my sintaxis??

Read only

0 Likes
1,102

Hi Hund,

1)The routines in scripts needs only two parameters but you are using three in your FORM statement.

2)The form defintion should be like this

<b>FORM X TABLES p_input STRUCTURE ITCSY

p_output STRUCTURE ITCSY.</b>

instead of

FORM X TABLES p_input STRUCTURE ITCSY

p_input1 STRUCTURE ITCSY

p_output STRUCTURE ITCSY.

3) All your USING parameters will be in P_INPUT structure and CHANGING parameters will be in P_OUTPUT structure

Note: Plz reward all helpful answers..

Thanks,

Vinay

Read only

Former Member
0 Likes
1,102

/: PERFORM GET_VALUE IN PROGRAM ZPROG

/: USING &V_VAR1&

/: CHANGING &V_VAR2&

/: ENDPERFORM

Coding of the calling ABAP program:

REPORT ZPROG.
FORM GET_VALUE TABLES IN_PAR STUCTURE ITCSY
                     OUT_PAR STRUCTURE ITCSY.
data: l_field type i,
      l_field2 type i.
*-- if the date is in MM/DD/YYYY format


READ TABLE IN_PAR WITH KEY ‘MHNK-AUSDT’.

IF SY-SUBRC = 0.
l_field = IN_PAR-VALUE.

ENDIF.

l_field2 = l_field + l_field2.

READ TABLE OUT_PAR WITH KEY ‘V_VAR2’.
IF SY-SUBRC = 0.
  OUT_PAR-VALUE = l_field2.
ENDIF.

ENDIF.

Read only

Former Member
0 Likes
1,102

How can I send 3 or 4 parameters on the sapscript???

Read only

0 Likes
1,102

you can any number of parameters in perform statement.

/: PERFORM <form> IN PROGRAM <prog>

/: USING &INVAR1&

/: USING &INVAR2&

......

/: CHANGING &OUTVAR1&

/: CHANGING &OUTVAR2&

......

/: ENDPERFORM

Coding of the calling ABAP program:

you need to

READ TABLE IN_PAR WITH KEY ‘INVAR1’.

to get the first passed value

READ TABLE IN_PAR WITH KEY ‘INVAR2’.

to get the first passed value

similarly to pass the value to the out table

READ TABLE OUT_PAR WITH KEY ‘OUTVAR1’.

to get the first passed value

READ TABLE OUT_PAR WITH KEY ‘OUTVAR2’.

to get the first passed value

and we need to modify the OUT_PAR table.

Read only

alejandro_lpez
Contributor
0 Likes
1,103

Hi,

You can send several parameters form sapscript like in a report program:

DEFINE &VSERNR(I77)& TYPE C

/: DEFINE &VSERNR2(I77)& TYPE C

/: PERFORM TOMARSERIES IN PROGRAM ZENS

/: USING &MKPF-MBLNR&

/: USING &MKPF-MJAHR&

/: USING &MSEG-MATNR&

/: USING &MSEG-ZEILE&

/: CHANGING &VSERNR&

/: CHANGING &VSERNR2&

/: ENDPERFORM

regards,

Alejandro.