cancel
Showing results for 
Search instead for 
Did you mean: 

do calculation in SAPScript

Former Member
0 Kudos

can I do the calculation in SAPScript form directly?

i want to do the calculation like this, (to show the unit price is divided by

&UPRICE& = &KOMVD-KBETR& / &KOMVD-KPEIN&

but it seems not work when i type this statement in the form (SE71)

how can i do?

or need to write in Program and pass the value to the form?

if need to wrie program, how can I loop it to get the unit price of the item, coz it don't point to the KOMVD-KSCHL..(means its value is empty)..

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi sky,

you can perform calculations using subroutines.

Just go through this link, I hope it will help you.

[Subroutines|http://help.sap.com/saphelp_nw70/helpdata/en/d1/803279454211d189710000e8322d00/frameset.htm]

Regards,

Nidhi Kothiyal

Answers (6)

Answers (6)

Former Member
0 Kudos

Call a subroutine from your script and do the calculation and returened back the calculated value of price from subroutine.

Do like this

Code to be written in script

Perform f0100_calc in program ztest

Using &VA1&

Changing &VAR2&

endperform

Code to be written in program ztest (subroutine pool)

FORM f0100_calc TABLES p_input_table STRUCTURE itcsy (table to hold the values passed from script)

p_output_table STRUCTURE itcsy. (table to hold the values passed to script)

READ TABLE p_input_table WITH KEY name = u2018VAR1 (should be in samecase as in script').

If sy-subrc = 0.

VAR1 = VAR1 * 100 (do whatever calculation you want)

Endif.

READ TABLE p_output_table WITH KEY name = u2018VAR2'

IF sy-subrc = 0.

MOVE VAR1 TO p_output_table-value.

MODIFY p_output_table INDEX sy-tabix.

Endif.

Endform.

Hope this will help you.

Former Member
0 Kudos

have a look a this

[link|;

thanks

Former Member
0 Kudos

Hi,

You can not do any mathematical calculations in Script directly.

However, this can be done by using subroutine. You can either define a subroutine in the driver program or in any other program. And then you can call this subroutine in your script.

/:PERFORM calculate IN PROGRAM zcalculate

/:USING &fre_chrg&

/:CHANGING &netval&

/:ENDPERFORM

rgrds,

Shweta

Former Member
0 Kudos

Hi ,

Please try to code like this

PERFORM GET_PAY_OEXPL IN PROGRAM Z_report

USING &ZTERM1&

USING &ZTERM2&

CHANGING &Zsum&

then in report (subroutine )

code for the sum of these two number

regards

prashant.

Former Member
0 Kudos

Hi Sky,

If you need to do some few 1 line calculations in SAP Script , you can do it in the Script itself.There is no need to call a routine for that.Use Command Line symbol in the script and write your code .

For Eg :-

/: IF &UPRICE& = '0'.

/: &UPRICE& = &KOMVD-KBETR& / &KOMVD-KPEIN&

/: ENDIF.

Regards ,

Samreen.

Former Member
0 Kudos

Hi,

You can write like this in the window where you want to perform the calculation.

/: DEFINE lv_var ____________ (what ever way you want).

or you can say

/: PERFORM calucalte_sum IN PROGRAM ZTEST_CALCULATE USING ____ CHANGING ____

and in the program ZTEST_CALCUALTE you can write the FORM, ENDFORM and pass it back to the script.

Thanks

manish