cancel
Showing results for 
Search instead for 
Did you mean: 

Form Script Caluclations

Former Member
0 Kudos

Hi Experts,

I want to do some small mathematical calculations in the Script form. I want to subtract one field vale from other field & display the result. How can i do it? I must write a procedure for that or is there any other method.

Regards

Rajendra

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

In the Script form u cannot do any caluclations, u can only assign values.

U can use perform and endperform, and do the required calculations in the program.

For the details abt the perform use the following link

http://help.sap.com/saphelp_47x200/helpdata/en/d1/803279454211d189710000e8322d00/frameset.htm

Let me know if u face any problem.

Regards

Former Member
0 Kudos

HI,

Do the Calculation by writing a perform inside the SAPSCRIPT

perform calc in program ZPROGRAM using &W_INPUT1&

&W_INPUT2&

changing &W_OUTPUT&

In the ZPROGRAM.

FORM CALC TABLES INVAR STRCTURE ITCSY

OUTVAR STRCTURE ITCSY.

data: var1 type i,

var2 type i,

result yupe i.

READ TABLE INVAR with key FIELD = 'W_INPUT1'

if sy-subrc = 0.

var1 = INVAR-VALUE.

endif.

READ TABLE INVAR with key FIELD = 'W_INPUT2'

if sy-subrc = 0.

var2 = INVAR-VALUE.

endif.

Result = VAR2 - Var1.

READ TABLE OUTVAR with key FIELD = 'W_OUTPUT'

if sy-subrc = 0.

OUTVAR-VALUE = Result.

endif.

Modify OUTVAR index SY-Tabix.

ENDFORM.

So, in the SAPSCRIPT, the 'W_OUTPUT' will have the Difference of &W_INPUT1& and &W_INPUT2&

Regards

Sudheer

former_member480923
Active Contributor
0 Kudos

Hi,

Do the Calculation by writing a perform routine inside the SAPSCRIPT

Sample Code

perform sub_calc in program <ZPROGRAM> using &W_INPUT1&
                                                                                &W_INPUT2&
                                                                     changing &W_OUTPUT&

and in the Program 
FORM SUB_CALC TABLES INVAR STRCTURE ITCSY
                                          OUTVAR STRCTURE ITCSY.
............ Your Code
ENDFORM. 

Former Member
0 Kudos

you ca nachive in two ways

1. doing the calculation in print program before displaying that.

2. writing the code in layout... editor by using the elemetn (NAME CALCULATE )there alos you can. call the elemet when u reqire. example as follows

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'CALCULATE'

EXCEPTIONS

ELEMENT = 1

WINDOW = 2.

IF SY-SUBRC NE 0.

PERFORM PROTOCOL_UPDATE.

ENDIF.

Message was edited by:

Naresh Reddy