08-19-2007 10:27 AM
hi
what is the best way to do sum
i have like that ex.
reg_field sum field
100 100
200 300
300 600
tankes i reward
08-19-2007 10:39 AM
Hi
SOrt the internal table and then use the Control break statements and do the sum
see the following
All this AT NEW, AT FIRST, AT END OF and AT LAST are called control break statements of Internal tables and are used to calculate the TOTALS based on sertain key fields in that internal table
FIrst to use these statements the ITAB has to be sorted by the key fields on whcih you need the SUM of the fields.
Some time you will get * when mopving data from this int table to other table using these commands
so you have to use
READ TABLE ITAB INDEX SY-TABIX in AT..ENDAT..if you are using other fields between them
DATA: sflight_tab TYPE SORTED TABLE OF sflight
WITH UNIQUE KEY carrid connid fldate,
sflight_wa LIKE LINE OF sflight_tab.
SELECT *
FROM sflight
INTO TABLE sflight_tab.
LOOP AT sflight_tab INTO sflight_wa.
AT NEW connid.
WRITE: / sflight_wa-carrid,
sflight_wa-connid.
ULINE.
ENDAT.
WRITE: / sflight_wa-fldate,
sflight_wa-seatsocc.
AT END OF connid.
SUM.
ULINE.
WRITE: / 'Sum',
sflight_wa-seatsocc UNDER sflight_wa-seatsocc.
SKIP.
ENDAT.
AT END OF carrid.
SUM.
ULINE.
WRITE: / 'Carrier Sum',
sflight_wa-seatsocc UNDER sflight_wa-seatsocc.
NEW-PAGE.
ENDAT.
AT LAST.
SUM.
WRITE: / 'Overall Sum',
sflight_wa-seatsocc UNDER sflight_wa-seatsocc.
ENDAT.
ENDLOOP.
<b>Reward points for useful Answers</b>
Regards
Anji
08-19-2007 10:33 AM
Hi,
if you need sum in internal table, then in loop of that table code "sum". it will sum entire column and keep in header row.
or use ADD <FIELD_NAME> TO MTOT.
If you clear your question, I can give solution exactly.
Regards
Rajiv singh.
08-19-2007 12:07 PM
hi rajiv
i have a table with field of hours like below and i wont to add another field
to my table that sum all hours until this field
hours sum hours
100----
100
200----
300
300----
600
400----
1000
i reward
Regards
08-19-2007 12:09 PM
chek this out it wil solve ur prob
data: begin of it occurs 3,
a type i,
b type i value 0,
end of it.
it-a = 100.
it-b = 0.
append it.
it-a = 200.
it-b = 0.
append it.
it-a = 300.
it-b = 0.
append it.
data a type i.
loop at it.
"it-a.
it-b = a + it-a.
a = it-b.
write: / it-a, it-b.
endloop.
reward if useful
Fresher
08-19-2007 10:39 AM
Hi
SOrt the internal table and then use the Control break statements and do the sum
see the following
All this AT NEW, AT FIRST, AT END OF and AT LAST are called control break statements of Internal tables and are used to calculate the TOTALS based on sertain key fields in that internal table
FIrst to use these statements the ITAB has to be sorted by the key fields on whcih you need the SUM of the fields.
Some time you will get * when mopving data from this int table to other table using these commands
so you have to use
READ TABLE ITAB INDEX SY-TABIX in AT..ENDAT..if you are using other fields between them
DATA: sflight_tab TYPE SORTED TABLE OF sflight
WITH UNIQUE KEY carrid connid fldate,
sflight_wa LIKE LINE OF sflight_tab.
SELECT *
FROM sflight
INTO TABLE sflight_tab.
LOOP AT sflight_tab INTO sflight_wa.
AT NEW connid.
WRITE: / sflight_wa-carrid,
sflight_wa-connid.
ULINE.
ENDAT.
WRITE: / sflight_wa-fldate,
sflight_wa-seatsocc.
AT END OF connid.
SUM.
ULINE.
WRITE: / 'Sum',
sflight_wa-seatsocc UNDER sflight_wa-seatsocc.
SKIP.
ENDAT.
AT END OF carrid.
SUM.
ULINE.
WRITE: / 'Carrier Sum',
sflight_wa-seatsocc UNDER sflight_wa-seatsocc.
NEW-PAGE.
ENDAT.
AT LAST.
SUM.
WRITE: / 'Overall Sum',
sflight_wa-seatsocc UNDER sflight_wa-seatsocc.
ENDAT.
ENDLOOP.
<b>Reward points for useful Answers</b>
Regards
Anji