Application Development and Automation 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: 
Read only

Doubt in table connection

Former Member
0 Likes
578

Hi all,

I have a small problem, i have 2 'Z' tables with same fields. but some records are different from the both. i want to write mismatched records. How to do that?

Ex: ztab1 & ztab2 have matnr field but in ztab1 have a,b,c records. in ztab2 have a, b,c, ab, bc, cd, ef. i want to print only ab, bc, cd, ef. plz give soln.

Gowri

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
557

Hi

declare 3 int tables ITAB1 ITAB2 ITAB_DIFF with same fields

select * from ZTAB1 into table ITAB1.

Select * from ZTAB2 into table ITAB1.

Loop at ITAB1.

Read table ITAB2 with key a = itab1-a b = itab1-b c = itab1-c.

if sy-subrc <> 0.

move-corresponding iTAB2 to ITAB_DIFF,

append ITAB_DIFF.

endif.

clear ITAB_DIFF.

endloop.

use ITAB_DIFF

Reward points for useful Answers

Regards

Anji

4 REPLIES 4
Read only

amit_khare
Active Contributor
0 Likes
557

loop at itab1.

read itab2 into wa_itab2 with key fld1 = fld2.

if sy-subrc <> 0.

append wa_itab2 to itab3.

endif.

endloop.

Now Itab3 has different records.

Regards,

Amit

Reward all helpful replies.

Read only

Former Member
0 Likes
558

Hi

declare 3 int tables ITAB1 ITAB2 ITAB_DIFF with same fields

select * from ZTAB1 into table ITAB1.

Select * from ZTAB2 into table ITAB1.

Loop at ITAB1.

Read table ITAB2 with key a = itab1-a b = itab1-b c = itab1-c.

if sy-subrc <> 0.

move-corresponding iTAB2 to ITAB_DIFF,

append ITAB_DIFF.

endif.

clear ITAB_DIFF.

endloop.

use ITAB_DIFF

Reward points for useful Answers

Regards

Anji

Read only

Former Member
0 Likes
557

data:

itab1 like table of ztab1 with header line,

itab2 like table of ztab2 with header line,

w_lines1 type i,

w_lines2 type i.

select * from ztab1 into itab1.

select * from ztab2 into itab2.

sort itab1 by matnr.

sort itab2 by matnr.

describe table itab1 lines w_lines1.

describe table itab2 lines w_lines2.

if w_lines1 GE w_lines2.

loop at itab1.

read table itab2 with key matnr = itab1-matnr binary search.

if sy-subrc ne 0.

write:/ itab1-matnr.

endif.

endloop.

else.

loop at itab2.

read table itab1 with key matnr = itab2-matnr binary search.

if sy-subrc ne 0.

write:/ itab2-matnr.

endif.

endloop.

endif.

Read only

Former Member
0 Likes
556

hi gowri,

u can use inner join on both tables with where condition on matnr.

where ztab1matnr ne ztab2matnr.

this may work...

please reward if useful..

regards,

prashant