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 scripts

Former Member
0 Likes
548

hi.. all,

i am struck with some problem in script, can any one help me.

my problem is i hv two fields total price & total qty, i hve to get the out put. i wrote the code for that. like that i have 4-5 fields or blocks, i need to get the total of all those fields.

1. total price * qty = total amount

2. total price * qty = total amount

3. total price * qty = total amount

4. total price * qty = total amount

-


sum = xxxxxxxxxxxx

-


the sum shld change dynamically as per no. of records, i mean, if i hve two records i shld get sum of total amount for two records. plz help me.

4 REPLIES 4
Read only

Former Member
0 Likes
495

Hi,

Its very simple.

Take 2 variables (VAR1, VAR2).

VAR1 - total of all fields within the record.

VAR2 - Sum of all records.

If you are in LOOP,

for each field while calculating total amount, add total amount to one variable (VAR1).

total amount = total price * total quantity

var1 = var1 + total amount.

Then for each end of record (before end loop), assign the var1 to var2.

var2 = var2 + var1.

clear var1.

regards,

Subba.

Read only

Former Member
0 Likes
495

loop at lt_tab.

sum = price * qty.

totsum = totsum + sum.

endloop.

you can use this for any number of records...

RS

Read only

Former Member
0 Likes
495

you can not do the manupulation of fields in script.

so write a PERFORM & define that FORM in any z program & pass all your field values & do the sum & revert it to the script.

regards

srikanth

Read only

dani_mn
Active Contributor
0 Likes
495

Hi use 'SUM' statement at end of your loop to get total.

LIKE.

LOOP AT itab.

AT LAST.

SUM.

call your text element to write values.

ENDAT.

ENDLOOP.

Regards,

Wasim Ahmed