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: 

internal tables.

former_member487858
Active Participant
0 Kudos

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.

Thanks

Shree.

1 ACCEPTED SOLUTION

ian_maxwell2
Active Participant
0 Kudos

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.
      exit.
    else.
      v_found = 'X'.
    endif.

    clear wa_trdir2.
  endloop.

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

  clear wa_trdir1.
endloop.

~Ian

3 REPLIES 3

naimesh_patel
Active Contributor
0 Kudos

You can loop on ITAB1 and read the ITAB2 with the same account number.

If you found the entry don't do anything

If you don't found the entry than move it to some other table and update some flag column in the ITAB1.

Regards,

Naimesh Patel

Former Member
0 Kudos

Hi,

Same as what Naimesh said.......

Loop at itab1.

read table itab2 with key a/c number = itab1-a/c number.

if sy-subrc ne 0.

itab1-flag = 'X'.

modify itab1.

endif.

endloop.

Now you have 5 records flagged in itab1 which are the different from itab2.

Regards,

DNP

ian_maxwell2
Active Participant
0 Kudos

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.
      exit.
    else.
      v_found = 'X'.
    endif.

    clear wa_trdir2.
  endloop.

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

  clear wa_trdir1.
endloop.

~Ian