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

comparing two internal tables

kiran_k8
Active Contributor
0 Likes
638

Hi Folks,

How to compare two internal tables?Can we do even if they have different structure but some similar data?

Thanks,

K.Kiran.

Message was edited by:

Kiran K

1 ACCEPTED SOLUTION
Read only

alejandro_bindi
Active Contributor
0 Likes
326

If they have the same structure:


IF it_1[] = it_2[].
   " Tables contents are the same
ELSE.
   " Tables contents are different
ENDIF. 

If they have different structure, you probably must loop one of the tables, and inside read the other, then compare field by field.

Or if you don't need the contents (just comparing) you can do this, for example:


LOOP AT it_1 INTO wa_1.
   READ TABLE it_2 WITH KEY field2 = wa_1-field2
                            field5 = wa_1-field5
                   TRANSPORTING NO FIELDS.
   IF sy-subrc = 0.
      " Record is on both tables (field2 and field5 are the fields in common for both tables).
   ENDIF.
ENDLOOP.

Regards.

Please reward points if helpful.

2 REPLIES 2
Read only

alejandro_bindi
Active Contributor
0 Likes
327

If they have the same structure:


IF it_1[] = it_2[].
   " Tables contents are the same
ELSE.
   " Tables contents are different
ENDIF. 

If they have different structure, you probably must loop one of the tables, and inside read the other, then compare field by field.

Or if you don't need the contents (just comparing) you can do this, for example:


LOOP AT it_1 INTO wa_1.
   READ TABLE it_2 WITH KEY field2 = wa_1-field2
                            field5 = wa_1-field5
                   TRANSPORTING NO FIELDS.
   IF sy-subrc = 0.
      " Record is on both tables (field2 and field5 are the fields in common for both tables).
   ENDIF.
ENDLOOP.

Regards.

Please reward points if helpful.

Read only

Former Member
0 Likes
326

Hi K K,

I think we can not compare the internal table if their structure is diffrent but i think we can compare the internal table fields whic is common in both the internal tables.

If IT_tab-field = IT_tab1-field.

business logic.

endif.

if helpfull reward points.

Anees Ahmed

9886358645