2007 Oct 25 2:23 PM
How to get sum for a particular field in internal table?
I hv used sorted table.
I want group the field for which I want to take sum <b>depending</b> on currency field.
I am not able to use AT- NEW - END - END AT
2007 Oct 25 2:34 PM
Hello,
Take one more internal table with your required field as a group criteria and amount.
Like:
data: begin of itab occurs 0,
fld1 type fld1,
wears type waers,
amount type dmbtr,
end of itab.
loop at <sorted_tab>.
move-corresponding <sorted_Tab> to itab.
collect itab.
clear itab.
endloop.After this ITAB will have the data with SUM on the amount field.
Regards,
Naimesh Patel
Hello,
Take one more internal table with your required field as a group criteria and amount.
Like:
data: begin of itab occurs 0,
fld1 type fld1,
wears type waers,
amount type dmbtr,
end of itab.
loop at <sorted_tab>.
move-corresponding <sorted_Tab> to itab.
collect itab.
clear itab.
endloop.After this ITAB will have the data with SUM on the amount field.
Regards,
Naimesh Patel
2007 Oct 25 2:34 PM
Hello,
Take one more internal table with your required field as a group criteria and amount.
Like:
data: begin of itab occurs 0,
fld1 type fld1,
wears type waers,
amount type dmbtr,
end of itab.
loop at <sorted_tab>.
move-corresponding <sorted_Tab> to itab.
collect itab.
clear itab.
endloop.After this ITAB will have the data with SUM on the amount field.
Regards,
Naimesh Patel
2007 Oct 25 2:38 PM
Suhas,
If you want to use AT- NEW - END - END AT based on Currency Field then the Currency Field should be the <b>First</b> field in the Internal table.....
Chandra.
2007 Oct 25 2:48 PM
hi,
do the following:
declare one more itab to collect the sum, say itab2 and one temporary variable v1 type waers to store currency key.
loop at itab1 into wa1.
if sy-tabix = 1.
v1 = wa1-waers.
move wa1 to wa2.
endif.
else.
if v1 = wa1-waers.
wa2-amount = wa2-amount + wa1-amount.
else.
append wa2 to itab2.
v1 = wa1-waers.
clear wa2.
endif.
endloop.
2007 Nov 07 2:59 PM
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |