cancel
Showing results for 
Search instead for 
Did you mean: 

collect funtionality on sorted tab whose nonkeyfields are not numeric

Former Member
0 Kudos

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.

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

Former Member
0 Kudos

I appreciate your quick response. however, im still unable to use collect on currency/amount fields.

Thanks,

kranthi.

Former Member
0 Kudos

Can you please post your actual code here?

Thanks,

Srinivas

former_member181962
Active Contributor
0 Kudos

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.

former_member188685
Active Contributor
0 Kudos

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