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

Split internal table into 2 internal table based on a condition

Former Member
0 Likes
6,692

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

13 REPLIES 13
Read only

Former Member
0 Likes
2,895

Hi,

Hope the following similar Thread will help you regarding your problem.

Thanks.

Nitesh

Read only

Former Member
0 Likes
2,895

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.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
2,895

if u dont want to use loop concept

While Selecting & populating the table

"populate it seperately" changing ur where clause

Read only

0 Likes
2,895

Delete statements on such huge amount of records will be a problem.

because it must rebuild the index once again.

Read only

0 Likes
2,895

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.

Read only

0 Likes
2,895

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 .

Read only

0 Likes
2,895

Just show how ur filling the data to the itab....

Read only

0 Likes
2,895

Just show how ur filling the data to the itab....

Read only

0 Likes
2,895

I use select query from table DFKKKO to populate the internal table.

Read only

Former Member
0 Likes
2,895

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.

Read only

Former Member
0 Likes
2,895

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

Read only

Former Member
0 Likes
2,895

I think keeping the current scenario, delete is much better in performance than any other like looping.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
2,895

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.