09-17-2008 9:38 AM
hi experts
i have an interanl table:
DATA: BEGIN OF i_data OCCURS 0,
lifnr LIKE mseg-lifnr,
grund LIKE mseg-grund,
matnr LIKE mseg-matnr,
ebeln LIKE mseg-ebeln,
erfmg LIKE mseg-erfmg,
erfme LIKE mseg-erfme,
shkzg LIKE mseg-shkzg,
grtxt LIKE t157e-grtxt,
kvgr1 LIKE knvv-kvgr1,
bezei LIKE tvv1t-bezei,
name1 LIKE lfa1-name1,
stras LIKE lfa1-stras,
ort01 LIKE lfa1-ort01,
telf1 LIKE lfa1-telf1,
kunnr LIKE lfa1-kunnr,
ktabg LIKE vbka-ktabg,
preis LIKE eipa-preis,
bwaer LIKE eipa-bwaer,
peinh LIKE eipa-peinh,
bprme LIKE eipa-bprme,
END OF i_data.
which is sorted according to fields lifnr and grund
i want to take from this table every row with the same lifnr and grund and to sum the field erfmg of all rows
with the same two fields to a variable or another table.
how can i do this
thanks
amit
Edited by: amit walden on Sep 17, 2008 10:39 AM
09-17-2008 9:58 AM
Hi Amit,
Do like the following,
Consider itab1 contains number of records.
copy itab1 values to itab2,
itab2[] = itab1[].
sort itab2 by fld1 fld2.
delete adjacent duplicate from itab2 comparing fld1 fld2.
loop at itab2.
loop at itab1 where fld1 eq itab2-fld1 and fld2 eq itab2-fld2.
itab2-fld3 = itab1-fld3 + itab2-fld3.
endloop.
endloop.
loop at itab2.
write : / itab2-fld1, itab2-fld2, itab2-fld3.
endloop.
I hope the above coding will help you to solve your problem.
Regards,
Harish
09-17-2008 9:44 AM
hi,
you have to declare anothe rinternal table with fields lifnr, grund and erfmg, and code something like:
LOOP AT itab.
AT END OF grund.
SUM.
itab2-lifnr = itab-lifnr.
itab2-grund = itab-grund.
itab2-erfmg = itab-erfmg.
APPEND itab2.
ENDAT.
ENDLOOP.
hope this helps
ec
09-17-2008 9:45 AM
Hi
Declare one more internal table
Types : begin of ty_lifnr,
lifnr LIKE mseg-lifnr,
grund LIKE mseg-grund,
erfmg LIKE mseg-erfmg,
end of ty_lifnr.
data : i_lifnr type table of ty_lifnr.
data : wa_lifnr type ty_lifnr.
loop at i_data.
wa_lifnr-lifnr = i_data-lifnr.
wa_lifnr-grund = i_data-grund.
wa_lifnr-erfmg = i_data-erfmg.
collect wa_lifnr into i_lifnr
endloop.
Regards
MD
09-17-2008 9:58 AM
Hi Amit,
Do like the following,
Consider itab1 contains number of records.
copy itab1 values to itab2,
itab2[] = itab1[].
sort itab2 by fld1 fld2.
delete adjacent duplicate from itab2 comparing fld1 fld2.
loop at itab2.
loop at itab1 where fld1 eq itab2-fld1 and fld2 eq itab2-fld2.
itab2-fld3 = itab1-fld3 + itab2-fld3.
endloop.
endloop.
loop at itab2.
write : / itab2-fld1, itab2-fld2, itab2-fld3.
endloop.
I hope the above coding will help you to solve your problem.
Regards,
Harish