Skip to Content
0
Aug 01, 2022 at 03:05 PM

How to delete a values by comparing two internal tables

83 Views

Hi together,

I am trying to compare two internal tables in order to eliminate the duplicates. The idea is that I do not wish for one of the internal table to be sorted as I do not wish to change the order of the values, thus I created a new internal table. The code is as follows:

t_itab = p_itab.

SORT t_itab ASCENDING.
DELETE ADJACENT DUPLICATES FROM t_itab COMPARING ALL FIELDS.

LOOP AT p_itab INTO wa_tab.
p_index = sy-tabix.
READ TABLE t_itab with key XXX TRANSPORTING NO FIELDS.
IF sy-subrc <> 0. "If the entry does not exist in the new internal table then delete from p_itab.
DELETE p_itab INDEX p_index.
ENDIF.
ENDLOOP.

The issue that I am having is on the READ TABLE statement. The fields of the internal tables varies as they may change depending on the condition table that is used in the program. Thus I cannot hard code the WITH KEY statement as in the future the fields may change.

Does anyone know how can I delete a value that does not exist in one of the internal tables, without using the READ TABLE statement?

Thank you all in advance!

Attachments

image.png (15.1 kB)