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: 

Finding unmatched records between two tables

Former Member
0 Kudos

Hi,

Suppose there are two tables - A and B and they have a couple of common key fields. I want to select those records from A which do not have a matching record in B. What will be most efficient way to do that?

Thank you.

7 REPLIES 7

geetha_k
Active Participant
0 Kudos

Hi,

1. First to select records from 2 tables into internal tables.

2. then read both tables and slect the unmatched records into one internal table

Former Member
0 Kudos

Loop on table A.

Read Table B with Keys.

If Sy-subrc = 0.

        • Record in A is found in B.

else.

        • Record in A NOT found in B.

endif.

endloop.

Former Member
0 Kudos

Hi,

Fetch all the records from both the table A & B.


Loop at <itab_a> into <wa_a>.
<lw_tabix> = sy-tabix.
read table <itab_b> into <wa_b> with key .............  .
if sy-subrc = 0.
delete <itab_A> index <lw_tabix>.
clear <lw_tabix>.
endif.
endloop.

Now <itab_a> will contains the record which is not available in <itab_b>.

Regards

Dillip Sahoo

Former Member
0 Kudos

Hi,

Is your issue is solved now??

Regrads

Dillip

0 Kudos

Hi Dilip,

Not really. The reason being that looping is what I wanted to avoid and it seems that there is no other way to do it.

0 Kudos

Hey,

Look at this link .......... i think this may help you a bit to achieve ur requirement

http://help.sap.com/saphelp_470/helpdata/en/fc/eb35f8358411d1829f0000e829fbfe/content.htm

&

Comparing Internal Tables: -

Internal tables can be compared with the operands that are used to compare other data objects. The most important criteria for comparing the internal table are the number of lines they contain. The larger the number of lines, the larger it is for comparisons. If the both the internal tables have same number of lines, then they are compared line by line. The operands used for comparisons are LE, LT, GE, GT, EQ, NE.

Except for EQ, the comparison stops at the first pair of components that identifies the condition false.

anup_deshmukh4
Active Contributor
0 Kudos

null

Edited by: Anup Deshmukh on May 27, 2010 12:16 PM

Edited by: Anup Deshmukh on May 27, 2010 12:16 PM