2016 May 12 9:49 AM
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
D
Thanks and Regards,
Uma
2016 May 12 10:02 AM
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
2016 May 12 10:17 AM
Hi team,
Can any one suggest solution to the above issue.
Thanks and Regards,
Uma
2016 May 12 10:37 AM
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
2016 May 12 10:25 AM
2016 May 12 10:28 AM
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
2016 May 12 10:49 AM
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.
.
2016 May 12 10:51 AM
Hi,
Have you tried the Range table concept which I mentioned above.
Regards
Raj
2016 May 12 11:17 AM
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.
2016 May 15 10:32 PM
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
2016 May 12 10:33 AM
You could have used an inner join if they were physical tables, but with internal tables loop is the only option.
Regards,
Anupama
2016 May 12 10:55 AM
You can prepare a range table on field: field1 and then use below syntax:
Delete it_tab1 where field1 in r_fld1.
2016 May 12 12:15 PM
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
2016 May 12 11:04 AM
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.
2016 May 12 11:14 AM
'Delete adjacent duplicates' statement will keep one copy of duplicate records. But his requirement is to delete all duplicate occurring records.
2016 May 12 11:11 AM
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.
2016 May 12 11:20 AM
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.
2016 May 12 11:54 AM
2016 May 12 12:05 PM
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
2016 May 12 1:09 PM
2016 May 13 7:32 AM
HI Uma ,
Try this below syntax.It may be help's u.
Delete <ITAB> where <Condition>