Skip to Content
author's profile photo Former Member
Former Member

Numerical Variable in SAP script

hi

please i have a requirement to generate the some fields on as SAP Script form.But it's not outputing any time i print.This is what i did

/:declare &my_tax& = &REGUP-WRBTR& " i want to declare a field my_tax like REGUP-WRBTR

/:declare &my_tax& = 0.05 * &REGUP-WRBTR& " tax = 0.05*the gross(REGUP-WRBTR)

i now placed &my_tax& on the form,yet that particular field was blank on printing

Pls i'll appreciate if some one can help look at the syntax.

The idea is to compute the tax at runtime and output it on the form.

Many thanks.

Add a comment
10|10000 characters needed characters exceeded

Related questions

5 Answers

  • Posted on Feb 08, 2012 at 09:33 AM

    Hi,

    In Sapscript if you want to assign some value, then use :=

    eg. /:declare &my_tax& := 0.05

    Then it will work.

    Regards,

    Harsh Bansal

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Bansal ,

      I get you but the requirement is to display a tax field on the form.This field should contain the computation of the gross field(&REGUP-WRBTR&) multiplied by 0.05.The output should be displayed on the form which is the tax.

      Now if i declare like below

      /:declare &my_tax& := 0.05

      will it be fine to say

      /:&my_tax& * &REGUP-WRBTR&

      then how do i display the computation on the form.

      2) please how do i display a preview of the form containing the required element.

      Most times i print.i want to be able to preview the changes before printing.

      Many thanks

  • author's profile photo Former Member
    Former Member
    Posted on Feb 08, 2012 at 10:01 AM

    HI friend,

    Also to declare a variable you can use DEFINE in Scripts. Declare doesn't work her.

    Use the below code

    /: DEFINE &MY_TAX& = &REGUP-WRBTR&

    /: DEFINE &MY_TAX& := 0.05 * &REGUP-WRBTR&

    &MY_TAX&

    If you have any doubt revert back to me i will help you.

    Thanks,

    Sri Hari

    Edited by: srihari.kumar on Feb 8, 2012 3:31 PM

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      HI friend,

      Correct i too got the same. Can i know how you are passing the value to the variable &REGUP-WRBTR&. Because this variable is 0 when i checked it in run time.

      So just check whether this field is holding the value in debug mode.

      In my case i did not pass the value for that variable from the driver program.

      You try passing that value from the driver program and it will work fine. Else try to do the calculation in an subroutine and do.

      If any issues please revert back to me i will help you.

      Thanks,

      Sri Hari

      Edited by: srihari.kumar on Feb 8, 2012 5:00 PM

  • Posted on Feb 08, 2012 at 11:27 AM

    you have to do this calculation in a subroutine.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 08, 2012 at 11:58 AM

    Hi,

    To do the calculation, you need to use -

    PERFORM subroutine CHANGING your_var

    you will have to perform calculation in subroutine in the program.

    Regards,

    Harsh Bansal

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Yes friend you are right.

      You can calculate the code after sy-subrc check but the value must be passed to "OUT_PAR-value" because this is the variable which will be updated in the internal table "OUT_PAR". This table is passed to the smart form.

      Also you can write the code after displaying the smartform. Because if you give at beginning it will show the below statement cannot be reached.

      SO after the close form function you can give this peace of code.

      READ TABLE OUT_PAR with key 'TOT'. "Read the table using the key for which you need to pass the value in this case it will be VAR1

      if sy-subrc eq 0.

      CALCW = 2 * 10. "Perform your calculation ex: REGUP-WRBtr * 0.05

      OUT_PAR-value = CALCW. "Pass it to the output internal table variable

      endif.

      MODIFY OUT_PAR INDEX 1. "Modify the output internal table so the value will be passed to the script

      If you face issues still please revert back to me.

      Thanks,

      Sri Hari

      Edited by: srihari.kumar on Feb 10, 2012 12:31 PM

  • author's profile photo Former Member
    Former Member
    Posted on Feb 08, 2012 at 01:43 PM

    Hi,

    You can do the calculation in a Z program by calling a perform statement from SAP script and returning the calculated value back to the script. Then print this returend value in SAP script.

    You can refer this link for further details.

    Link: http://wiki.sdn.sap.com/wiki/display/ABAP/SubroutinesAndTheirUseIn+SAPScript

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.