Skip to Content
avatar image
Former Member

Form Script Caluclations

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • avatar image
    Former Member
    Jan 16, 2007 at 12:20 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 16, 2007 at 12:23 PM

    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. 

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 16, 2007 at 12:35 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 16, 2007 at 01:09 PM

    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

    Add comment
    10|10000 characters needed characters exceeded