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

abap

Former Member
0 Likes
668

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

7 REPLIES 7
Read only

Former Member
0 Likes
638

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.

Read only

Former Member
0 Likes
638

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

Read only

Former Member
0 Likes
638

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^

Read only

0 Likes
638

i am not getting the sum plz tel me

Read only

0 Likes
638

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.

Read only

Former Member
0 Likes
638

Hi khadar,

Use the steps given by Naren followed by the code given by me.

Rajesh.

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
638

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.