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.
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
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