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

SAP Script : Calculations with text elements

Former Member
0 Likes
663

Dear All,

How can I do calucations in SAP Script.

Actually I have 2 text elements Total and tax. And I would like to display Sub Total which is Total - Tax.

I wonder how can I do that directely in SAP Script without Editing printprogram

Thank you for your inputs.

Regards

Venkat.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
588

Hi...

On your SAP script write:

/: PERFORM subrutine IN PROGRAM Zprogram

/: USING &PAR1&

/: CHANGING &PAR2&

/: ENDPERFORM

PS: You can use as many USING AND CHANGING as you need.

And the zprogram goes;

FORM subrutine TABLES t_in STRUCTURE itcsy

t_out STRUCTURE itcsy.

data: par1 type n.

  • Read the value on PAR1

READ TABLE t_in WITH KEY 'PAR1'.

CHECK sy-subrc = 0.

PAR1 = t_IN-value.

  • DO WHATEVER YOU NEED TO DO

ADD 1 TO PAR1.

....

  • SEND THE VALUES BACK

READ TABLE t_OUT WITH KEY 'PAR2'.

t_sal-value = PAR1 .

MODIFY t_OUT INDEX sy-tabix.

ENDFORM.

4 REPLIES 4
Read only

Former Member
0 Likes
588

You cannot do any calculation in script.

Why you want to do in the form instead of print program.

If the print program is standard and if you decided not to change that program you can call a subroutine from the

form, In that form u can do the necessary calculations.

Hope this helps..

Thanks,

Vamshi

Read only

0 Likes
588

Hi Vamshi,

Thanks for quick info. All points to you.

I will include a Subroutine.

Regards

Venkat.

Read only

Former Member
0 Likes
589

Hi...

On your SAP script write:

/: PERFORM subrutine IN PROGRAM Zprogram

/: USING &PAR1&

/: CHANGING &PAR2&

/: ENDPERFORM

PS: You can use as many USING AND CHANGING as you need.

And the zprogram goes;

FORM subrutine TABLES t_in STRUCTURE itcsy

t_out STRUCTURE itcsy.

data: par1 type n.

  • Read the value on PAR1

READ TABLE t_in WITH KEY 'PAR1'.

CHECK sy-subrc = 0.

PAR1 = t_IN-value.

  • DO WHATEVER YOU NEED TO DO

ADD 1 TO PAR1.

....

  • SEND THE VALUES BACK

READ TABLE t_OUT WITH KEY 'PAR2'.

t_sal-value = PAR1 .

MODIFY t_OUT INDEX sy-tabix.

ENDFORM.

Read only

0 Likes
588

Dear Gabriel,

Thank you very much for your reply and code included, This is very helpful.

I guess, my problem is solved and I will allot full points to you, while closing this thread.

Regards

Venkat