2008 Sep 25 10:40 AM
Hi,
my sorted table with unique key field1 field2 is defined like:
field1 keyfield
field2 keyfield
field3
field4
i would like to get a sum of field3 and field4 of all entries "for each new field1 field2" and write it out.
field1 = 1
field2 = 100
sum(field3)
sum(field4)
write it out.
field1 = 1
field2 = 200
sum(field3)
sum(field4)
write it out.
field1 = 2
field2 = 100
sum(field3)
sum(field4)
write it out.
Q: Should I use LOOP and AT NEW FIELD1/FIELD2 or can i use another way for that ?
Thanks,
Gordon
2008 Sep 25 10:43 AM
Hi,
my sorted table with unique key field1 field2 is defined like:
field1 keyfield
field2 keyfield
field3
field4
create one more table similar to the above table
loop the first table.
secondtable-field1 = firsttable-field1.
secondtable-field2 = firsttable-field1
secondtable-field3 = firsttable-field1
secondtable-field4 = firsttable-field1
collect secondtable.
endloop.
Regards
MD
Hi,
my sorted table with unique key field1 field2 is defined like:
field1 keyfield
field2 keyfield
field3
field4
i would like to get a sum of field3 and field4 of all entries "for each new field1 field2" and write it out.
field1 = 1
field2 = 100
sum(field3)
sum(field4)
write it out.
field1 = 1
field2 = 200
sum(field3)
sum(field4)
write it out.
field1 = 2
field2 = 100
sum(field3)
sum(field4)
write it out.
Q: Should I use LOOP and AT NEW FIELD1/FIELD2 or can i use another way for that ?
Thanks,
Gordon
2008 Sep 25 10:43 AM
2008 Sep 25 10:43 AM
Hi,
my sorted table with unique key field1 field2 is defined like:
field1 keyfield
field2 keyfield
field3
field4
create one more table similar to the above table
loop the first table.
secondtable-field1 = firsttable-field1.
secondtable-field2 = firsttable-field1
secondtable-field3 = firsttable-field1
secondtable-field4 = firsttable-field1
collect secondtable.
endloop.
Regards
MD
2008 Sep 25 10:44 AM
Hi
loop at itab.
res = res + itab1-field3 + itab-field4.
endloop.
2008 Sep 25 10:44 AM
Hello
Do Following:
1. Sort Internal table by Field1 Field2
2. Do Loop... At New Field2... Sum... Endat.... Endloop.
Thanks
Amol Lohade
2008 Sep 25 10:45 AM
declare an internal table same as itab...
first do a sort on internal table...
sort itab by field1 field2.
loop at itab.
itab1-field1 = itab-field1.
itab1-field2 = itab-field2.
itab1-field3 = itab-field3.
itab1-field4 = itab-field4.
collect itab1.
endloop.
loop at itab1.
write:/itab1-field1, itab1-field2, itab1-field3, itab1-field4.
endloop.
2008 Sep 25 10:46 AM
2008 Sep 25 10:54 AM
thanks for your help.
what is the better way to avoid performance issue.
1. loop / at new field or
2. second itab and use collect itab.
note: my table is selected from VBRP (invoice items) - very huge
2008 Sep 25 10:55 AM
Hi
The second option is to be avoided.
2. second itab and use collect itab.Regards
Pavan
2008 Sep 25 10:58 AM
2008 Sep 25 10:49 AM
2008 Sep 25 11:00 AM
if field1 and field2 are non numeric then
collect those values to other itab...
2008 Sep 25 11:01 AM
2008 Sep 25 11:03 AM
hi,
then you cannot use "collect" statement.
you will have to first sort table based on field1 field2.
then you will have to use LOOP AT and AT NEW field2.
2008 Sep 25 11:11 AM
Then do it like this.
loop at itab into wa.
at new field2.
move wa-field1 to it2-field1.
move wa-field2 to it2-field2.
endat.
at end of field2.
sum.
move wa-field3 to wa1-field3.
move wa-field4 to wa1-field4.
append wa1 to it2.
endat.
endloop.
| User | Count |
|---|---|
| 6 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |