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

Sapscript adding variables

Former Member
0 Likes
2,538

hi all,

i have the sap script in which i want to add two variables so in that can i use this?

sum = var1 + var2.

is it possible?

if no then what is the alternate for this?

thanxx....

6 REPLIES 6
Read only

Former Member
0 Likes
1,201

plzz reply back..

thanx a lot.

Read only

0 Likes
1,201

Yes very much possible.

You can write like this in the window where you want to perform the calculation.

/: DEFINE lv_var ____________ (what ever way you want).

or you can say

/: PERFORM calucalte_sum IN PROGRAM ZTEST_CALCULATE USING ____ CHANGING ____

and in the program ZTEST_CALCUALTE you can write the FORM, ENDFORM and pass it back to the script.

Regards,

S.Dakshna Nagaratnam.

Read only

Former Member
0 Likes
1,201

one way is to create a program(ztest_add) and in the attributes declare it as sub routine pool in SE38.

u do ur calculation part here. and call this in ur sap script.

plz chk this link where it is explained:

http://help.sap.com/saphelp_470/helpdata/EN/d1/803279454211d189710000e8322d00/content.htm

Read only

Former Member
0 Likes
1,201

Hi

In script need to code like this:

/: PERFORM GET_SUM IN PROGRAM Z_TEST
/: USING &VAR1& 
/: CHANGING &VAR2&
/: CHANGING &SUM&
/: ENDPERFORM.

After this you can use the value &SUM& in that window

In program Z_TEST code like this :

FORM get_address TABLES input_tab STRUCTURE itcsy
output_tab STRUCTURE itcsy.

DATA: lv_sum LIKE bseg-dmbtr,
           lv_var1 LIKE bseg-dmbtr,
           lv_var2 like bseg-dmbtr.

READ TABLE input_tab WITH KEY name = 'VAR1'.
IF sy-subrc = 0.
  lv_var1 = input_tab-value.
ENDIF.

READ TABLE input_tab WITH KEY name = 'VAR2'.
IF sy-subrc = 0.
  lv_var2 = input_tab-value.
ENDIF.

lv_sum = lv_var1 + lv_var2.

READ TABLE output_tab WITH KEY name = 'SUM'.
IF SY-SUBRC = 0.
output_tab-value = lv_sum.
MODIFY output_tab TRANSPORTING value
WHERE name = 'SUM'.
ENDIF.

Read only

Former Member
0 Likes
1,201

hi,

try this

/: PERFORM Sum IN PROGRAM ZSum

/: USING &var1&

/: USING &var2&

/: CHANGING &var3&

/: ENDPERFORM

Read only

Former Member
0 Likes
1,201

ok