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

merging records in itab...

Hi all,

My dilemma for today is as follows. I have a record set that is keyed on matnr werks pspnr. In addition, each row contains fields for qty1 qty2 qty3 qty4 date week month quarter year. I would like to merge...or sum...those records together by week before display in my ALV grid. In JAVA this would be a complicated process...a series of loops that involved summing the qty fields. Is there a fairly concise way for me to perform this task in ABAP?

regards,

Mat

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Aug 30, 2006 at 06:46 PM

    Have a look at the COLLECT statement.

    Rob

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 30, 2006 at 06:54 PM

    Hi Mathew,

    Use COLLECT statement to mergre records. COLLECT will sum up all numeric fields in an internal table if all other non-numeric fields are same.

    You can give the COLLECT statement resultant internal table to the ALV grid.

    To know more about COLLECT, just browse this link

    http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/collect.htm

    Thanks,

    Vinay

    Add a comment
    10|10000 characters needed characters exceeded

    • If the reqt is to summarize by week, COLLECT will not give you the deisred result. You will have to loop at the itab & use the Control break statement AT NEW & then Use SUM. ex

      loop at itab.

      AT NEW itab-week.

      SUM.

      • move the summarized data to a diff variable

      ENDAT.

      ENDLOOP.

      ~Suresh

  • author's profile photo Former Member
    Former Member
    Posted on Aug 30, 2006 at 07:02 PM

    If you are summing by week, then the date field really isn't relevant. If you do not remove the date field, and it contains unique values within a given week, then the collect statement won't give you what you need. If you can remove the date field, this would be the way to go.

    Add a comment
    10|10000 characters needed characters exceeded

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.