Skip to Content
author's profile photo Former Member
Former Member

collect funtionality on sorted tab whose nonkeyfields are not numeric

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Posted on Nov 18, 2005 at 05:45 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 18, 2005 at 05:50 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 18, 2005 at 06:02 PM

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

    Thanks,

    kranthi.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 18, 2005 at 07:44 PM

    here is my requirement

    internal table 1(sorted)

    field1(10) -|-filed2(10) |-FIELD3-|-FIELD4-|-field5-|

    type c keyf-|- 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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.