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: 

Get the Common from Two Internal Tables with same structure

Former Member
0 Kudos

Hi ,

I need to get the Common data from Two Internal Tables with same structure with using the looping method.

For e.g.

I have two internal table say ITAB1 and ITAB2.

ITAB1 has values A,B,C,D,E,F

ITAB2 has values A,H,B,Y,O

Output at runtime should be : A,B

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi mohit,

1. If u want to compare all fields,

for matching purpose,

then we can do like this.

2.

report abc.

data : a like t001 occurs 0 with header line.

data : b like t001 occurs 0 with header line.

loop at a.

LOOP AT B.

IF A = B.

WRITE 😕 'SAME'.

ENDIF.

endloop.

ENDLOOP.

regards,

amit m.

7 REPLIES 7

Former Member
0 Kudos

Do you mean, you want to know the common columns between these tables?

Regards,

Ravi

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

Say itab1 and itab2 has the common field f1.

loop at itab1.

loop at itab2 where f1 = itab1-f1.

write : / itab2-f1.

endloop.

endloop.

Former Member
0 Kudos

Hello Mohit,

Use this code.

loop at itab1.

read table itab2 with key f1 = itab1-f1.

if sy-subrc = 0.

write: f1.

endif.

endloop.

If useful reward.

Vasanth

Former Member
0 Kudos

Hi mohit,

1. If u want to compare all fields,

for matching purpose,

then we can do like this.

2.

report abc.

data : a like t001 occurs 0 with header line.

data : b like t001 occurs 0 with header line.

loop at a.

LOOP AT B.

IF A = B.

WRITE 😕 'SAME'.

ENDIF.

endloop.

ENDLOOP.

regards,

amit m.

Former Member
0 Kudos

Hi Mohit

If you can use the looping then itz simple to extract the details.

 loop at itab1.
       read table itab2 with key fld1 = itab-fld1.
       if sy-subrc ne 0.
          delete itab where fld1 = itab-fld1.
       endif.
  endloop.

By end of this loop you will have all the entries in itab1 which are common both in itab1 and itab2.

Kind Regards

Eswar

Former Member
0 Kudos

Sorry my mistake i want it wiothout using the LOOPING Method.

Something like ITAB1 IN ITAB2 etc...

0 Kudos

no u cant do it with out atleast one loop.