Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

regarding merge

Former Member
0 Likes
1,288

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,251

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

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.

9 REPLIES 9
Read only

Former Member
0 Likes
1,252

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

Read only

0 Likes
1,251

thanks folwell, i solved this problem by ur code.

very useful.

Read only

Former Member
0 Likes
1,251

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.

Read only

0 Likes
1,251

hey folwell.

while testing i found that logic for the below pattern is missing.(pls refer ur logic)

if the internal table contains below values.

200 001A 12345678 00000000 2000

200 001A 12345678 00000000 5000

200 001A 12345678 20050202 100

200 001A 12345678 20050202 200

200 001A 12345678 20050202 300

200 011A 12345678 00000000 5000 <-

the output becomes like this

200 001A 12345678 00000000 7000 (merged)

200 001A 12345678 20050202 100

200 001A 12345678 20050202 200

200 001A 12345678 20050202 300

below record is not displaying.

200 011A 12345678 00000000 5000

what should i change here..

ambichan.

Read only

0 Likes
1,251

Hello Ambi,

Have you tried the COLLECT statement? When SAP has given you an option to do it automatically, trying to do it manually is just inviting trouble.

Regards,

Anand Mandalika.

P.S. Also please mark the thread as "unanswered", so that more users will want to see the problem and answer it.

Read only

0 Likes
1,251

thankyou mandalika,

I solved using COllect statement itself.

very easily.really experts...aaha.

ambichan.

Read only

0 Likes
1,251

Then you could have given me 10 points

Read only

0 Likes
1,251

sorry actually, that button(problem solved) is disabled at ur reply section.

Next time let me check out.

thankyou.

ambichan

Read only

0 Likes
1,251

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?