Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

internal tables.

HI all,

I have two internal tables.

tab1 contains 20 records with a/c number as the key field

tab2 contains 15 records of tab1 with the a/c number as the key field.

Now I want to get only the 5 records from the tab1 which is not in tab2.

How do I do this.

Can any one give some suggestions.



Former Member
Former Member replied

Assuming that the number of records that you gave is just an example and that you actually have to process a larger number of records, there are a few ways to process the records:

- loop + loop

- loop + sequential read

- loop + binary search

- loop + loop using a parallel cursor

These will of course vary in performance. Your best tehnique for comparing two tables with a large number of records would be a parallel cursor technique.

A parallel cursor technique will actaully get you a performance of n+m (where n is the number of records in the first table and m is the number of records in the second)

The following is an example of this code

v_pos1 = 0.

clear wa_trdir1.
loop at i_trdir1 into wa_trdir1.

  clear v_found.
  clear wa_trdir2.
  loop at i_trdir2 into wa_trdir2
  from v_pos1.

    v_pos1 = sy-tabix.

    if     wa_trdir2-name < wa_trdir1-name.
      write:/ wa_trdir2-name, 'in table 2 but not in table 1'.
    elseif wa_trdir2-name > wa_trdir1-name.
      v_found = 'X'.

    clear wa_trdir2.

  if v_found is initial.
    write:/ wa_trdir1-name, 'in table 1 but not in table 2'.
    write:/ wa_trdir1-name, 'in table 1 and in table 2'.

  clear wa_trdir1.


0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question