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: 

How to delete a values by comparing two internal tables

Raxph
Participant
0 Kudos
923

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!

2 REPLIES 2

saundattikar
Participant
0 Kudos
772

Hello,

Try using FM CTVB_COMPARE_TABLES_2. This FM can give you the desired results.

Thanks

Rohan

Sandra_Rossi
Active Contributor
0 Kudos
772

3 remarks:

  1. Comparing two internal tables doesn't require to eliminate the duplicates, it depends on the exact context and requirements.
  2. A second internal table is not required, you may define a Secondary Key on the original internal table, if it's just about reading it in another order.
  3. You may use READ TABLE with a dynamic list of components.

(see ABAP documentation for more information)