2007 May 22 5:35 AM
hello abap masters,
in my requirement,
there are three fields in an internal table
data: begin of itab1,
field1(3) type c,
field2(3) type c,
field3 type p.
data:end of itab1.
now i should calculate total of all (only) field3 's for each fied1,field2 combination and store them in itab2 table, which has only two fields from itab1, ie. field2,field3.
can some one help.
thank you.
2007 May 22 5:39 AM
Hi
SORT ITAB1 BY FIELD1 FIELD2 FIELD3.
LOOP AT ITAB1.
AT END OF FIELD2.
SUM.
READ TABLE ITAB1 INDEX SY-TABIX.
MOVE-CORRESPONDING ITAB1 TO ITAB2.
APPEND ITAB2.
ENDAT.
CLEAR ITAB2.
ENDLOOP.
Now Itab2 will have your required sums and fields.
Reward points if useful
Regards
Anji
hello abap masters,
in my requirement,
there are three fields in an internal table
data: begin of itab1,
field1(3) type c,
field2(3) type c,
field3 type p.
data:end of itab1.
now i should calculate total of all (only) field3 's for each fied1,field2 combination and store them in itab2 table, which has only two fields from itab1, ie. field2,field3.
can some one help.
thank you.
2007 May 22 5:38 AM
Hi,
try this
sort itab1 by field1 field2.
loop at itab1
itab2-field1 = itab2-field1 + itab1-field1.
itab2-field2 = itab2-field2 + itab1-field2
at new field2
append itab2.
endat
endloop
---Patil
2007 May 22 5:39 AM
Hi Saritha,
Create another table itab3 of type itab1 and then use below code.
loop at itab1.
collect itab1 to itab3.
endloop.
loop at itab3.
itab2-field2 = itab3-field2.
itab2-field3 = itab3-field3.
append itab2.
endloop.
Reward points if useful.
Regards,
Atish
2007 May 22 5:39 AM
Hi
SORT ITAB1 BY FIELD1 FIELD2 FIELD3.
LOOP AT ITAB1.
AT END OF FIELD2.
SUM.
READ TABLE ITAB1 INDEX SY-TABIX.
MOVE-CORRESPONDING ITAB1 TO ITAB2.
APPEND ITAB2.
ENDAT.
CLEAR ITAB2.
ENDLOOP.
Now Itab2 will have your required sums and fields.
Reward points if useful
Regards
Anji
2007 May 22 5:40 AM
HI Saritha,
try this logic..
SORT ITAB1 BY FIELD1 FIELD2 FIELD3.
LOOP AT ITAB1.
AT END OF FIELD2.
SUM.
READ TABLE ITAB1 INDEX SY-TABIX.
ITAB2-FIELD2 = ITAB1-FIELD2.
IATB2-FIELD3 = IATB1-FIELD3.
APPEND ITAB2.
ENDAT.
CLEAR ITAB2.
ENDLOOP.
OR
SORT ITAB1 BY FIELD1 FIELD2 FIELD3.
LOOP AT ITAB1.
AT NEW FIELD2.
READ TABLE ITAB1 INDEX SY-TABIX.
ITAB2-FIELD2 = ITAB1-FIELD2.
LOOP AT ITAB1 WHERE FIELD2 = ITAB2-FIELD2.
ITAB2-FIELD3 = ITAB2-FIELD3 + ITAB1-FIELD3.
ENDLOOP.
APPEND ITAB2.
ENDAT.
CLEAR ITAB2.
ENDLOOP.
Regards
SAB
2007 May 22 5:51 AM
Hi
sort itab1 by f1 f2 f3.
loop at itab1
at end of f3.
sum.
itab3-f2 = itab2-f2.
itab3-f3 = itab2-f3
append itab2.
endat.
clear itab2.
endloop.
Reward All Helpfull Answers........
2007 May 22 5:51 AM
DATA : WTAB1 LIKE ITAB1.
SORT ITAB1 BY F1 F2.
LOOP AT ITAB1.
ITAB2-F2 = ITAB1-F2.
AT END OF F2.
SUM.
ITAB2-F3 = ITAB1-F3.
APPEND ITAB2.
END AT.
ENDLOOP.
REGARDS
SHIBA DUTTA
2007 May 22 5:52 AM
2007 May 22 6:00 AM
hi saritha,
try like this,
data:itab2 like itab1 occurs 0 with header line.
sort itab by fld1, fld2.
loop at itab1.
itab2-fld1 = itab1-fld1 + itab1-fld2 + itab1-fld3.
itab2-fld2 = itab1-fld1.
append itab2.
endloop.
if helpful reward some points.
with regards,
suresh babu aluri.