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

Calculating difference in SAP Script

Former Member
0 Likes
755

Hello All,

I have 2 variables &REGUP-WRBTR& and &REGUP-SKNTO& passed to sap script from print program. I want to calculate thier difference in the script and display the value. I am using.

/: DEFINE &NET_AMOUNT& = &REGUP-WRBTR& - &REGUP-SKNTO&

This is not working. Could anyone please suggest how to solve this?

Regards

Indrajit

3 REPLIES 3
Read only

Former Member
0 Likes
501

Hi Indrajit,

try it

/: DEFINE &NET_AMOUNT&

&NET_AMOUNT& = &REGUP-WRBTR& - &REGUP-SKNTO&

Regards,

Allan Cristian

Read only

Former Member
0 Likes
501

You only have limited commands in SAPscript, and they do not include arithmatic.

You either have to perform the subtraction in your print program, or call a subroutine from your SAPscript.

Regards,

Nick

Read only

varma_narayana
Active Contributor
0 Likes
501

Hi indrajit.

You cannot perform any arithmetic operations in Layout set text elements.

But we can acheive this using the PERFORM command.

Eg:

In the window :

/: DEFINE &NET_AMOUNT& = '0'

/: PERFORM F_CALC_DIFF IN PROGRAM ZREP01

/: USING &REGUP-WRBTR&

/: USING &REGUP-SKNTO&

/: CHANGING &NET_AMOUNT&

/: ENDPERFORM

  • Net amount = &NET_AMOUNT&

In the program ZREP01 define the Subroutine:

FORM F_CALC_DIFF TABLES INTAB STRUCTURE ITCSY

OUTTAB STRUCTURE ITCSY.

DATA : V1 TYPE REGUP-WRBTR,

V2 TYPE REGUP-WRBTR,

V3 TYPE REGUP-WRBTR.

READ TABLE INTAB INDEX 1.

V1 = INTAB-VALUE.

READ TABLE INTAB INDEX 2.

V2 = INTAB-VALUE.

V3 = V1 - V2.

WRITE V3 TO OUTTAB-VALUE LEFT-JUSTIFIED.

MODIFY OUTTAB INDEX 1.

ENDFORM.

This will give you the solution.

<b>Reward if Helpful.</b>