‎2008 Oct 31 8:47 AM
Hi,
I have a requirement where in a single internal table has to be split into 2 internal table based on value of a field present in that internal table.
eg: All records having cleared flag =' X' then it should be put into 1 internal table and all other records should be put into another internal table.
Since the internal table has about 5 million records , I want to avoid loop....endloop to do this task.
If you have any solution which will not use loop...endloop to split internal table, please post your comments.
thanks,
Arun
‎2008 Oct 31 8:50 AM
‎2008 Oct 31 8:50 AM
Hi,
Check following steps:
1. Create a temporary table say itab_temp. Move original data to this table :
itab_temp[] = itab_main[].2.
Delete itab_temp where variable = 'X'.
itab_1[] = itab_temp[].3.
refresh itab_temp.
itab_temp[] = itab_main[].
Delete itab_temp where variable = space.
itab_2[] = itab_temp[].itab1_1 contains data with space value and itab_2 contains data with value 'X'.
Thanks & Regards,
Navneeth K.
‎2008 Oct 31 8:51 AM
if u dont want to use loop concept
While Selecting & populating the table
"populate it seperately" changing ur where clause
‎2008 Oct 31 8:52 AM
Delete statements on such huge amount of records will be a problem.
because it must rebuild the index once again.
‎2008 Oct 31 9:09 AM
Hi,
Navneeth and Ram have provided the same solution.
Thanks for the solution.
Keshu has raised concern over the use of delete statments which will impact on the performance. If any one can resolve this issue, it would be great.
‎2008 Oct 31 9:42 AM
Using index while deleting can be faster ..
For example say your table name is itab1 .
SORT itab1 BY 'condition field' .
DESCRIBE TABLE itab1 lines l_lines .
READ TABLE itab1 WITH KEY 'condition field' = 'X'
l_record = sy-tabix .
itab2 = itab1 .
DELETE itab1 FROM 1 TO l_record .
DELETE itab2 FROM l_record TO l_lines.
I think this will be best in terms of performance .
‎2008 Oct 31 9:58 AM
‎2008 Oct 31 9:58 AM
‎2008 Oct 31 11:36 AM
I use select query from table DFKKKO to populate the internal table.
‎2008 Oct 31 8:51 AM
Hi Arun,
With out using LOOP you can do it as below.
1. Declare tow internal tables, ITAB1 and ITAB2.
2. You have your records in ITAB1. Now use the statement
ITAB1[] = ITAB2. This will replicate the records in both internal tables.
3. Now SORT the tables based on the field. As per your e.g. based on the FLAG.
4. Now, delete the records that you done want.
DELETE ITAB1 WHERE FLAG = 'X'.
DELETE ITAB2 WHERE FLAG NE 'X'.This should helpyou acheive the results.
Best Regards,
Ram.
‎2008 Oct 31 8:55 AM
HI Arun,
First assign value to another internal table and then delete where flag = 'X'.
itab1[] = itab2[].
delete from itab2[] where flag = 'X'.
Thanks,
Chidanand
‎2008 Oct 31 10:00 AM
I think keeping the current scenario, delete is much better in performance than any other like looping.
‎2008 Oct 31 10:16 AM
Might b usefull !!!
When you delete an entry from an internal table in ABAP, the system has to re-generate the index for all entries after your delete, slowing the report if you have many records to eliminate.
It is much quicker to do an insert of the correct records into a second table than to delete entries from the first. The reason for this is because the index is only generated for the newest element.
I've included the code below as an example where we achieved a 150X speed improvement. By removing the code that performs a delete on table th_vlpma and replacing it with an append to th_vlpmatmp, we were able to get these type of gains.
Code
*--- D01K919273 Begin delete
*--- Delete deliveries not to be processed
loop at th_vbuk.
delete th_vlpma where vbeln eq th_vbuk-vbeln.
endloop. " th_vbuk.
*--- D01K919273 End delete
*--- Begin add D01K919273
loop at th_vlpma into th_vlpmatmp.
read table th_vbuk with key vbeln = th_vlpmatmp-vbeln
binary search.
check sy-subrc ne 0.
append th_vlpmatmp.
endloop.
*--- End add D01K919273
Delete should be correct in this situation .... because it happens in a single step.