2010 Feb 02 4:47 PM
Hi all,
let's assume, I have the following internal table MY_TAB:
COL_1 | COL_2 | COL_3
A 1 1
B 2 2
C 3 3
D 3 4
E 3 5
I'd like to delete all rows, where the values in COL_2 and COL_3 are equal. That is, in the above table, the rows for A, B and C.
What's the most performant / fastest and efficient way to do this?
Thanks for any hints in advance!
Best regards,
Philipp
2010 Feb 04 8:39 AM
if the table has only short fields as above then ASSIGNING has no advantage.
Use it with broader tables.
But overall, the ASSIGNING is an additional contribution.
The wrong command for the DELETE gives a completely different scaling !!!
2010 Feb 02 4:55 PM
Hi,
Copy the internal table into Temp table say My_tab_tmp.
append line of my_tab to my_tab_tmp.
sort my_tab_tmp by col2 col3.
delete duplicate entries from my_tab_tmp by comparing col1 col2.
loop at my_tab_tmp into wa_my_tab_tmp.
read tbale my_tab into wa_tab with key col1 = wa_my_tab_tmp-col1 binary search.
if (wa_my_tab_tmp-col2 = wa_tab-col2) and (wa_my_tab_tmp-col3 = wa_tab-col3).
delete my_tab from wa_tab where col1 = wa_my_tab_tmp-col1.
endif.
endloop.
Regards,
Bharani
2010 Feb 03 9:44 AM
I do not understand other proposal.
The are two solutions possible
LOOP AT itab INTO wa.
IF ( wa-col2 = wa-col3).
DELETE itab INDEX sy-tabix.
ENDIF.
ENDLOOP.
If memory is not an issue and if many lines are to be deleted, then the APPEND in a new table is better.#
I would use that one in all cases where the conditions are complicated.
LOOP AT itab INTO wa.
IF ( wa-col2 <> wa-col3).
APPEND wa TO itab2.
ENDIF.
ENDLOOP.
refresh itab.
itab[] = itab2[].
Siegfried
2010 Feb 03 4:45 PM
Hi,
Try:
field-symbols: <f> like line of itab.
loop at itab assigning <f>.
if <f>-col1 = <f>-col2.
delete itab index sy-tabix.
endif.
endloop.
Regards,
Edited by: Diego Alvarez on Feb 3, 2010 5:45 PM
2010 Feb 04 6:49 AM
Hi
Assigning field symbols or looping the internal table by comnparison would be the best solution.
Siva
2010 Feb 04 8:39 AM
if the table has only short fields as above then ASSIGNING has no advantage.
Use it with broader tables.
But overall, the ASSIGNING is an additional contribution.
The wrong command for the DELETE gives a completely different scaling !!!
2010 Feb 04 9:09 AM
Hi Siegfred,
The aim of using "assigning" is to avoid copying each line of the table to the header structure and only change the memory address that is pointed by the field-symbol. In small tables, will not be noticeable difference, but when you have many thousands of lines you will notice it is faster, you will avoid the step of copying data from one place to another... I think so, though I could be wrong
Regards,
2010 Feb 07 11:18 AM
Hi all,
I think you gave me some useful hints for my problem! Thanks!
I might run some performance test and see what solution is the fastest...
Regards,
Philipp
2010 Feb 04 8:55 AM
Hi,
DELETE my_tab WHERE col2 EQ col3.
sorry, its my fault
Marcel
Edited by: MarcelKucharek on Feb 4, 2010 10:10 AM
Edited by: MarcelKucharek on Feb 4, 2010 10:11 AM