‎2006 Sep 07 3:37 PM
Hi all abap sxperts.
my problem:
I have an IT filled with some records.
I must have only one record for 'OPBEL' with the sum of one field.
example to explain better:
Opbel
now > 000444 10
000444 14
000022 30
000022 10.
I want > 000444 24
000022 40.
Help me, points for all.
Bye
‎2006 Sep 07 3:44 PM
I have a lot of numeric fields in the record that no need the sum
‎2006 Sep 07 3:39 PM
hi Brasi,
Use <b>Collect</b> statement after the values get populated into an internal table ..
Regards,
Santosh
‎2006 Sep 07 3:40 PM
Define a second internal table like the first. Loop at your internal table and use the collect statement to collect records into the second. The second table will contain unique entries and all numeric fields will be summed.
loop at itab.
collect itab into itab2.
endloop.
‎2006 Sep 07 3:44 PM
I have a lot of numeric fields in the record that no need the sum
‎2006 Sep 07 3:50 PM
Define the second table to contain just OPBEL and the field you want summed.
loop at itab.
move-corresponding itab to itab2.
collect itab2.
endloop.
‎2006 Sep 07 3:58 PM
Hi Rhino,
If you want to have this OPBEL back in original itab
after summing up into itab2, do this way after what
Michael has suggested.
loop at itab. "Michael's code
move-corresponding itab to itab2.
collect itab2.
endloop. "Michael's code
<b>Loop at itab.
read table itab2 with key OPBEL = itab-opbel.
if sy-subrc eq 0.
itab-<field> = itab2-<field>.
modify itab index sy-tabix.
endif.
endloop.</b>
This way, you will have all the data back in itab.
Hope this will hep you.
Regards,
Vivek
‎2006 Sep 07 3:55 PM
hi,
Try this code.
types : begin of t_itab,
fld(6),
num type i,
val type i,
end of t_itab.
data: itab type standard table of t_itab with header line,
itab2 type standard table of t_itab with header line,
lv_sum like itab-num.
sort itab by fld.
loop at itab.
lv_tabix = sy-tabix.
at end of fld.
sum.
lv_sum = itab-num.
clear itab.
read table itab index lv_tabix.
if sy-subrc = 0.
itab2 = itab.
itab2-num = lv_sum.
append itab2.
clear itab2.
endif.
endat.
endloop.
Regards,
Sailaja.
‎2006 Sep 07 3:56 PM
hi,
then you can loop at the internal table and add the field that you want in the other table.
itab1 : f1
f2
f3
f4
itab2 : f1
f2
loop at itab1.
v_field = v_field + itab1-f2.
at end of f1.
itab2-f1 = itab1-f1.
itab2-f2 = v_field.
append itab2.
clear v_field.
endat.
endloop.Regards,
Richa
Message was edited by: Richa Singh
‎2006 Sep 07 3:58 PM
As your requirement is to sum only the one field and not the other numeric fields..you can use the below logic...
Define an internal table itab with the structure
OPBEL,
ltot.
While you are collecting information for internal table IT you can initialise the values for itab and use COLLECT. If that is not possible ...you can
LOOP at IT.
itab-opbel = it-opbel.
itab-ltot = it-lnum.
collect itab.
endloop.
‎2006 Sep 07 4:03 PM
Hi,
data itab1 like itab occurs 0 with header line.
loop at itab.
itab1 = itab.
collect itab1.
endloop.
Now your itab will have
000444 24
000022 40.
Regards
Amole
‎2006 Sep 07 4:14 PM