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

Get the Common from Two Internal Tables with same structure

Former Member
0 Likes
2,364

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
Read only

Former Member
0 Likes
1,053

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.

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

7 REPLIES 7
Read only

Former Member
0 Likes
1,053

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

Regards,

Ravi

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
1,053

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.

Read only

Former Member
0 Likes
1,053

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

Read only

Former Member
0 Likes
1,054

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.

Read only

Former Member
0 Likes
1,053

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

Read only

Former Member
0 Likes
1,053

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

Something like ITAB1 IN ITAB2 etc...

Read only

0 Likes
1,053

no u cant do it with out atleast one loop.