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: 

Function module for comparing contents of two internal tables

Former Member
0 Kudos

Hi All,

Is there any function module to compare contents of two internal tables of same structure?

If yes please let me know.

Thanks in advance.

Amol

1 ACCEPTED SOLUTION

Former Member
0 Kudos

FM 'COMPARE_TABLES' does actually compare two tables, but the result you get is veeeery simple.

It doesn´t return differences or anything, just a 'T' for identical or an 'F' for different....

Is that good enough for you?

9 REPLIES 9

Former Member
0 Kudos

I´m afraid there is no standard FM to do this job....

You´ll have to do that manually.

Former Member
0 Kudos

FM 'COMPARE_TABLES' does actually compare two tables, but the result you get is veeeery simple.

It doesn´t return differences or anything, just a 'T' for identical or an 'F' for different....

Is that good enough for you?

0 Kudos

Thanks for replying.

This FM wouldnot suffice my needs. My requirement is to compare both internal tables and show only the contents and field where difference is occuring.

If you know any other FM or any suggestion, it would be helpful.

Thanks,

Amol

0 Kudos

Dummy coding:

data: it1, it2, it_differences,

wa1, wa2.

loop at it1 into wa1.

read table it2 with key field1 = wa1-field1 field2 = wa1-field2....

if sy-subrc <> 0.

append wa1 to it_differences.

endif.

endloop.

loop at it2 into wa2.

read table it1 with key field1 = wa2-field1 field2 = wa2-field2....

if sy-subrc <> 0.

append wa2 to it_differences.

endif.

endloop.

it_differences will contain all lines of it1 and it2 which do not have a counterpart.

Former Member
0 Kudos

Hi,

Have you tried transaction SCMP ?

Regards

Jürgen

Former Member
0 Kudos

No need wasting processor and execution time by calling out to FM to compare two tables of the same structure.

The best coding for this need is to do it yourself.

if INT_Tab1[] = INT_Tab2[].

" They contain the same values

else.

" They DO NOT contain the same values

endif.

0 Kudos

Hello,

Thats right - it's easy to compare 2 structures - but in the coding above you don't know which fields are different.

Additional to this coding you have to compare each field by using the abap-rtti.

have a look to:

CL_ABAP_TYPEDESCR

CL_ABAP_STRUCTDESCR

With this classes you will get all fields from the structure and then you can assign each field and compare

Rregards

Thomas

Edited by: Thomas Mader on Jan 9, 2008 3:27 PM

Former Member
0 Kudos

hi,

check out this link http://help.sap.com/saphelp_nw04/helpdata/en/2a/fa01d0493111d182b70000e829fbfe/content.htm

reward points if helpful

regards

Goutham.

Former Member
0 Kudos

Hi,

Check out the following program to compare two internal tables. Hope it would be helpful.

&----


*& Report TEST02

*&

&----


*&

*&

&----


REPORT ZRKS_TEST02.

&----


*&Type Definition

&----


types: begin of typ_tabl,

carrid type spfli-carrid,

connid type spfli-connid,

cityfrom type spfli-cityfrom,

end of typ_tabl.

&----


*& Result of Comparison.

&----


data: res type c.

&----


*& Internal Table Definition

&----


data: it_001 type table of typ_tabl,

it_002 type table of typ_tabl.

&----


*& Select statement for first table.

&----


select carrid connid cityfrom from spfli into corresponding fields of table it_001 where carrid = 'AA'.

&----


*& Select statement for second table.

&----


select carrid connid cityfrom from spfli into corresponding fields of table it_002 where carrid = 'AA'.

CALL FUNCTION 'COMPARE_TABLES'

IMPORTING

RESULT = res

TABLES

table_new = it_001

table_old = it_002.

write: res.

-----End of Program -


Regard,

Sravani

  • Please reward points if found helpful.*