Skip to Content
author's profile photo Former Member
Former Member

Function module for comparing contents of two internal tables

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

6 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 09, 2008 at 02:04 PM

    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?

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Amol Jaiswal

      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.

  • author's profile photo Former Member
    Former Member
    Posted on Jan 09, 2008 at 02:15 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • author's profile photo Former Member
    Former Member
    Posted on Jan 09, 2008 at 02:17 PM

    hi,

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

    reward points if helpful

    regards

    Goutham.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 10, 2008 at 04:45 AM

    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.*

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 09, 2008 at 01:59 PM

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

    You´ll have to do that manually.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 09, 2008 at 02:13 PM

    Hi,

    Have you tried transaction SCMP ?

    Regards

    Jürgen

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.