‎2006 Oct 27 5:36 AM
see in one internal table i have got quantity field so i want to sum that whole field.
i am writitn like this but not summing.
at end of charg.
sum
write 😕 it_mchb-clabs.
endat.
i want sum of it_mchb-clabs.
plz do help
‎2006 Oct 27 5:41 AM
Hi khadar,
U can use a variable to sumup the total.
use the following code,
total like mchb-clabs.
loop at it_mchb.
total = it_mchb-clabs.
at end of charg.
write 😕 total.
total = 0.
endat.
endloop.
regards,
Rajesh.
‎2006 Oct 27 5:42 AM
Hi,
Try sorting the internal table..And make the field CHARG is the first field in your internal table declaration..
SORT ITAB BY CHARG.
Thanks,
Naren
‎2006 Oct 27 5:53 AM
hi
good
but where is your sum statement,if u want to add the value of a quantity field and store it into the anopthery field, than you can loop the internal table and sum the quantity field and store that amount in another field and display it.
thanks
mrutyun^
‎2006 Oct 27 6:11 AM
‎2006 Oct 27 6:35 AM
Hi,
If I've got ur problem correctly, u have an internal table ITAB with many fields including field say COND & CURRENCY.
Now u wanna sum up CURRENCY for all similar values in COND.
This can be of ur help....
data: TOTAL like CURRENCY.
sort ITAB by COND.
loop at ITAB.
at new COND.
refresh TOTAL.
endat.
TOTAL = TOTAL + ITAB-CURRENCY.
at end of COND.
write: / TOTAL.
endat.
endloop.
‎2006 Oct 27 6:15 AM
Hi khadar,
Use the steps given by Naren followed by the code given by me.
Rajesh.
‎2006 Oct 27 6:30 AM
Hi,
Here is the sample program from ABAPDOCU.As stated earlier,charg should be first field in internal table it_mchb.
TYPES: BEGIN OF T_TYPE,
CODE(4),
SALES TYPE P,
DISCOUNT TYPE P,
END OF T_TYPE.
DATA: T TYPE STANDARD TABLE OF T_TYPE WITH NON-UNIQUE
DEFAULT KEY INITIAL SIZE 100,
WA_T TYPE T_TYPE.
...
LOOP AT T INTO WA_T.
AT FIRST.
SUM.
WRITE: /4 'Grand Total:',
20 WA_T-SALES, 40 WA_T-DISCOUNT.
ULINE. SKIP.
ENDAT.
WRITE: / WA_T-CODE,
20 WA_T-SALES, 40 WA_T-DISCOUNT.
AT END OF CODE.
SUM.
WRITE: / WA_T-CODE, 10 'Total:',
20 WA_T-SALES, 40 WA_T-DISCOUNT.
SKIP.
ENDAT.
ENDLOOP.