on 11-18-2005 5:40 PM
Hi,
i have a requirement to collect all the identical records i.e sort and sum by all indicatives for which i defined an internal table like this
sorted internal table
field1(char)--keyfield
field2(char)--keyfield
field3(CHAR).....(but currency amount will be stored, as-is in db too)
filed4(CURR).... currency field
field5(char)
i need to COLLECT all the records in such a way that the field3 should be added on all the identical records and same as with field 4. the values for field1, field2 and field4 wont change if the key is same. im unable to do that bcos the collect wontt support this requirement.
In short i need to collect field3 and field4
how should i do that. your help would be appreciated.
Thanks,
Kranthi.
here is my requirement
internal table 1(sorted)
field1(10)-|-filed2(10)|-FIELD3-|-FIELD4-|-field5-|
type ckeyf-|- type c-keyf|type c|-CURR-|-typec|
_______________________________________________________
though field3 is char, i need to add all the values because currency is stored in that field
field 4 is currency field
if the table contains entries like this
10000|0100|2000|3000|A
10000|0100|-200|-500|A
10000|0100|0500|0200|A
my final table needs to be like this
10000|0100|2300|2700|A
loop at itab1.
collect itab1 into ***
endloop.
it doesn't work and more over every non key field should be numeric to make this work..
how should my final internaltable look like and the process i need to follow. your help would be appreciated
Thanks,
Kranthi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You need to make 3rd field to number type to work with COLECT stmt or you have to loop the table and populate it to another internal table something like below
loop at itab.
read table newitab with key field1 = itab-f1
field2 = itab-f2
field5 = itab-f5.
if sy-subrc = 0.
newitab-f3 = newitab-f3 + itab-f3.
newitab-f4 = newitab-f4 + itab-f4.
modify newitab with index sy-tabix.
else.
newitab = itab.
append newitab.
endif.
endloop.
I appreciate your quick response. however, im still unable to use collect on currency/amount fields.
Thanks,
kranthi.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
try this
data: begin of itab occurs 0,
field1(char)--keyfield
field2(char)--keyfield
field3(CHAR).....(but currency amount will be stored, as-is in db too)
filed4(CURR).... currency field
field5(char)
end of itab.
data: begin of itab2 occurs 0,
field1(char)--keyfield
field2(char)--keyfield
field3 type amount field
filed4(CURR).... currency field
field5(char)
end of itab2.
loop at itab.
*move each element into itab2.
append itab2.
clear itab2
endloop.
use collect on the second internal table and move the contents back to the original table.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
take another field in your internal table.
which is of currency field.
try populate this also with the same values of the field3.
then collect. and transfer all the data to field3 after.
it should work.
regards
vijay
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
75 | |
9 | |
8 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.