Application Development 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: 

Comparing two Internal tables

Former Member
0 Kudos
2,201

Hi Team,

Is it possible to delete the entries from two internal tables which are same with out using loop.Please suggest solution.

Note: Loop is causing performance pb.

Internal Table1                         Internal Table2                      Result required

Field1                                      Field1                                   

A                                              A                                              C

   

B                                              B                                              D

C                                           

                                        

Thanks and Regards,

Uma

20 REPLIES 20

chabbi_mustapha
Explorer
0 Kudos
623

Hello ,

You can you DELETE instruction in ABAP on internal table , you can see more details using the ABAP documentation , you just click on the instruction and press F1,

Hope this will be useful,

Regards

0 Kudos
623

Hi team,

Can any one suggest solution to the above issue.

Thanks and Regards,

Uma

0 Kudos
623

Hi ,

you can do one thing.

Build range internal table and append entries of table 2.

then delete table 1 where entries in range table in one shot.

Regards

Raj

former_member197916
Active Participant
0 Kudos
623

hi,

how do you intend to compare without using loops.

0 Kudos
623

Hi Abhishek,

I understand with out using Loop very difficult,but still I am searching for an alternate solution.If I am using loop program taking 8 hours to complete which contains more data.

Thanks and Reagrds,

Uma

0 Kudos
623

Did you use binary search when comparing the tables ?

sort InternalTable1  by field1.                 

sort InternalTable2 by field 1.


* if there could be more of the same entries in the tables, then first make sure only 1 is left.

delete adjacent duplicates from internalTable1 comparing field1.

delete adjacent duplicates from internalTable2 comparing field1.


loop at InternalTable1 assigning <workarea>.

   read internalTable2 with key field1 = <workarea>-field1 binary search.

   if sy-subrc = 0.

     delete internalTable2 index sy-tabix.

    clear <workarea>-field1. "to be able to delete this entry from the source table after the loop.

   endif.

endloop.


delete internalTable1 where field1 is initial.



.

0 Kudos
623

Hi,

Have you tried the Range table concept which I mentioned above.

Regards

Raj

0 Kudos
623

Peter Jonker wrote:

Did you use binary search when comparing the tables ?

.

Better would be (if possible) to define the internal tables as HASHED or SORTED in the first place. Or put a secondary index on the internal tables.

Binary search is so last millenium.

if you define your internal tables correctly, you should be able to process using loops very efficiently.


0 Kudos
623

Hi Uma,

for large mass data, doing anything in the LOOP is much slower than mass processing statements like DELETE WHERE.


Still, I would try adding a deletion flag to each item, set the flag in a LOOP and use DELETE WHERE flag = 'X' at the end of the loop.

Next I would implement a poor man's table index management to benefit from the performance of the DELETE statement. Create a mapping table and work with an index table, i.e. a table containing the index of the entry in the original table. e.g.

Internal Table1                         Mapping                      Index Table

Field1                                      Index Field                                  

A                                              3 A                                              3

  

B                                              4 B                                              4

C                                              1 C                                              1

D                                              2 D                                              2  

The index are chosen in a way that all entries in the reference table have the lowest index.

With this, you can now DELETE WHERE index LE 2, then do the reverse mapping.

I used this once (class LCL_TRACE_INDEX) to benefit from the performance of FIND IN TABLE in pattern matching. You will have to decide if it is worth the effort.

Hope this helps,

JNN

Former Member
0 Kudos
623

You could have used an inner join if they were physical tables, but with internal tables loop is the only option.

Regards,

Anupama

pranay570708
Active Contributor
0 Kudos
623

You can prepare a range table on field: field1 and then use below syntax:

    Delete it_tab1 where field1 in r_fld1.

0 Kudos
623

Hi Pranay,

These are single values and not in sequence.Even sequence also I need to loop 50 lakhs records to place in range table.

Please suggest any other way.

Thanks and Regards,

Uma

prajeshdesai
Contributor
0 Kudos
623

Try below,


SELECT *

   FROM VBRP

   INTO TABLE IST_VBRP

   UP TO 10 ROWS

   WHERE VBELN IN P_VBELN.

SELECT *

   FROM VBRP

   INTO TABLE IST_VBRP1

   UP TO 5 ROWS

   WHERE VBELN IN P_VBELN.

   APPEND LINES OF IST_VBRP1 TO IST_VBRP.

   SORT IST_VBRP BY VBELN.

   DELETE ADJACENT DUPLICATES FROM IST_VBRP COMPARING VBELN.

Hope this helps.

0 Kudos
623

'Delete adjacent duplicates' statement will keep one copy of duplicate records. But his requirement is to delete all duplicate occurring records.

0 Kudos
623

Hi,

For comparing the two internal tables,Loop @ the first internal table and read the second internal table with key key and binary search.

Filter the differences in the way you want.

To avoid the performance in looping the internal table, Use Parallel Cursor Method.

I hope this answer will be helpful.

0 Kudos
623

Parallel cursor method is so last millenium. If the tables are correctly defined as HASHED or SORTED , or have secondary keys defined on them, then there is no need to use binary search or parallel cursor method.

HASHED and SORTED tables have been around for over 15 years. Secondary keys for over 5. I really don't understand why people persist on using techniques that have been superseded for so long.

Due to the wealth of obsolete advice on this thread, I've marked it as a discussion, not a question. At least that will deter those posting solely for points.

0 Kudos
623

Not everybody has the luxury to work on the latest release.

0 Kudos
623

As long as people don't state their software release in the original post (which happens maybe 1% of the time), one must assume that a somewhat recent release is being used, which would maybe include secondary keys but would certainly include hashed and sorted tables.

Thomas

0 Kudos
623

HASHED and SORTED have been available since 46c...

former_member185124
Participant
0 Kudos
623

HI Uma ,

Try this below syntax.It may be help's u.

Delete <ITAB> where <Condition>