Hi,
i Have internal table with fields like in e.g. below
and i wont to sum the Work days and put it in the last Colman
what is the Best way to do that?
Regards
i have this table without Colman sum_total (empty) .
what i wont is to spread the sum for all appearance of pernr in sum total Colman :
pernr kostl work_days sum_total 111 5555 5 13 111 5555 8 13 444 6666 10 15 444 6666 2 15 444 6666 3 15 555 5656 3 6 555 5656 3 6
Hi
You can try the following way.
data: begin of itab occurs 0,
pernr type char3,
ktosl type char4,
workd type i,
sumwr type i,
end of itab.
data: it_out like itab occurs 0 with header line.
itab-pernr = '111'.
itab-ktosl = '5555'.
itab-workd = 5.
append itab.
itab-pernr = '111'.
itab-ktosl = '5555'.
itab-workd = 8.
append itab.
itab-pernr = '444'.
itab-ktosl = '6666'.
itab-workd = 10.
append itab.
itab-pernr = '444'.
itab-ktosl = '6666'.
itab-workd = 2.
append itab.
itab-pernr = '444'.
itab-ktosl = '6666'.
itab-workd = 3.
append itab.
itab-pernr = '555'.
itab-ktosl = '5656'.
itab-workd = 3.
append itab.
itab-pernr = '555'.
itab-ktosl = '5656'.
itab-workd = 3.
append itab.
loop at itab.
collect itab into it_out.
clear it_out.
endloop.
clear itab.
loop at it_out.
itab-pernr = it_out-pernr.
itab-ktosl = it_out-ktosl.
itab-sumwr = it_out-workd.
modify itab transporting sumwr where pernr eq it_out-pernr
and ktosl eq it_out-ktosl.
endloop.
loop at itab.
write : itab-pernr, itab-ktosl, itab-workd, itab-sumwr, /.
endloop.
Reward points, if it is helpful.
Regards
Raja.
sort it by pernr kostl. data:sum_val type p. loop at itab. at new pernr. sum. sum_val = itab-work_days. endat. itab-sum_total = sum_val. modify itab transporting sum_total where pernr = itab-pernr and kostl = itab-kostl. endloop.
Hi Another simple way of doing this is using two internal tables.
lets say ur output table as you have shown is gi_out.
declare another table gi_pernr same structure as of gi_out.
gi_pernr[] = gi_out[] sort gi_pernr by pernr. delete adjacent duplicates from gi_pernr comparing pernr. loop at gi_pernr into gw_pernr. clear lv_days. loop at gi_out into gw_out where pernr = gw_pernr-pernr. lv_days = lv_days + gw_out-work_days. endloop. modify gi_out from gw_out transporting sum_total where pernr = gw_pernr-pernr. endloop.
.
This will surely work..
thnx,
Ags..
Add a comment