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

regarding merge

Could you pls help me below problem.

i have set of records in my internal table.

(records grouped by bizcode and date)

Code Bizcode GLcode date Amount.

200 001A 12345678 00000000 2000 - S1

200 001A 12345678 00000000 3000 - S2

200 001A 12345678 20050202 100

200 001A 12345678 20050202 200

200 001A 12345678 20050202 300

200 011A 12345678 00000000 2000 - S3

200 011A 12345678 00000000 3000 - S4

200 011A 12345678 20050203 300

200 011A 12345678 20050203 300

200 011A 12345678 20050203 300

goes on...

My requirement is want to merge records

S1 and S2 (ie,add Amount of Record S1+S2

and make single record)

similarly S3+S4 and make single record.

pls see below for required output.

i want to know how this can be adapted techincally

in internal table.

Code Bizcode GLcode date Amount.

200 001A 12345678 00000000 5000 (merged)

200 001A 12345678 20050202 100

200 001A 12345678 20050202 200

200 001A 12345678 20050202 300

-


200 011A 12345678 00000000 5000 (merged)

200 011A 12345678 20050203 300

200 011A 12345678 20050203 300

200 011A 12345678 20050203 300

ambichan.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Feb 08, 2005 at 03:29 AM

    I will assume your table is named my_table and is sorted by code, bizcode, glcode and date, all in ascending order.

    Allocate a duplicate table, I will call it my_table_copy.

    For simplicity, I will assume both tables have header lines.

    CLEAR my_table_copy.
    
    LOOP AT my_table.
    
      ON CHANGE OF code bizcode glcode.
         IF my_table-date = 0.
            my_table_copy = my_table.
            CONTINUE.
         ENDIF.
      ENDON.
    
      IF my_table-date = 0.
        my_table_copy-amount = my_table_copy-amount +
           my_table-amount.
        CONTINUE.
      ELSE.
        IF NOT my_table_copy is initial.
          APPEND my_table_copy.
          CLEAR my_table_copy.
        ENDIF.
        APPEND my_table_copy FROM my_table.
      ENDIF.
    
    ENDLOOP.
    
    * In case the entries with 0 date are at the end.
    
    IF NOT my_table_copy is initial.
      APPEND my_table_copy.
    ENDIF.
    
    * my_table_copy should now have the desired results

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 08, 2005 at 05:33 AM

    Hello Ambichan,

    In your internal table, the fields CODE , BIZCODE, GLCODE & DATE are all character based fields, while AMOUNT is the only numeric field. So the simplest way of summing up the amount values would be to use the <i><b>COLLECT</b></i> statement.

    1. Let us say your current internal table is ITAB. Declare another internal table ITAB1, that is exactly the same as ITAB.

    2. Loop at ITAB and collect the data into ITAB1. Assuming that ITAB has a header line, you could use something like this :

    loop at itab.
      collect itab into itab1.
    endloop.

    Regards,

    Anand Mandalika.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      I considered the use of COLLECT but you showed the following lines of data:

      200 001A 12345678 20050202 100

      200 001A 12345678 20050202 200

      200 001A 12345678 20050202 300

      and you indicated that you did NOT want these to be merged. I assumed you only wanted to merge when the date was = 0. Since the keys above are all the same, COLLECT would also merge these together.

      Have I misunderstood your request?

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.