‎2007 Dec 10 12:10 PM
Dear All
i have one internal table . 24 fields are avilable in that table . i want the sum for all fields.
How to get total?
Thanks and Regards
Suresh
‎2007 Dec 10 12:15 PM
using control command you can sum the field if they are neumaric. declare the itab1 of same structure of itab.
Loop at itab into <workarea>.
At end of <Field>
sum.
append <waarea> to itab1.
atend.
endloop.
‎2007 Dec 10 12:16 PM
Hi,
Check the following example:
DATA: BEGIN OF LINE,
COL1 TYPE C,
COL2 TYPE I,
COL3 TYPE I,
END OF LINE.
DATA ITAB LIKE HASHED TABLE OF LINE
WITH UNIQUE KEY COL1 COL2.
LINE-COL1 = 'A'.
DO 3 TIMES.
LINE-COL2 = SY-INDEX.
LINE-COL3 = SY-INDEX ** 2.
INSERT LINE INTO TABLE ITAB.
ENDDO.
LINE-COL1 = 'B'.
DO 3 TIMES.
LINE-COL2 = 2 * SY-INDEX.
LINE-COL3 = ( 2 * SY-INDEX ) ** 2.
INSERT LINE INTO TABLE ITAB.
ENDDO.
SORT ITAB.
LOOP AT ITAB INTO LINE.
WRITE: / LINE-COL1, LINE-COL2, LINE-COL3.
AT END OF COL1.
SUM.
ULINE.
WRITE: / LINE-COL1, LINE-COL2, LINE-COL3.
SKIP.
ENDAT.
AT LAST.
SUM.
ULINE.
WRITE: / LINE-COL1, LINE-COL2, LINE-COL3.
ENDAT.
ENDLOOP.
Regards,
Bhaskar
‎2007 Dec 10 12:17 PM
Using obsolete ADD-CORRESPONDING.
DATA: wa_sum LIKE LINE OF itab.
FIELD-SYMBOLS: <wa> LIKE LINE OF itab.
LOOP AT itab ASSIGNING <wa>.
ADD-CORRESPONDING <wa> TO wa_sum.
ENDLOOP.Use collect.
DATA: itab_sum ... " defined as table of same type as itab
LOOP AT itab ASSIGNING <wa>.
COLLECT <wa> INTO itab_sum.
ENDLOOP.itab_sum now contains the sum of all the numeric fields for all the character field combinations of your internal table.
matt
‎2007 Dec 10 12:20 PM
Hi,
You can use the collect statement.
Assume you have internal table itab with data.
Do as below :
Loop at itab into wa.
collect wa to itab2.
endloop.
or
loop at itab.
at end of field.
sum.
endat.
endloop.Thanks,
Sriram Ponna.
‎2007 Dec 10 12:32 PM