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

comparing two internal tables

HI all!

I have two internal tables with single field values as below :

1st Internal Table : A,B,C,D

2nd Internal Table : A,B,C,D,E,F,G,

Now I want to compare these two Int. tables and delete the second int. table with values which are not there in the first int. table.Any simple logic to get this.

Regards

Pavan

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

9 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jun 20, 2006 at 10:09 AM

    loop at itab_old.

    DELETE TABLE itab WITH TABLE KEY k1 = itab_old-k1 ... kn = itab_old-kn.

    endloop.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 20, 2006 at 10:10 AM

    hi

    DELETE TABLE itab WITH TABLE KEY k1 = v1 ... kn = vn.

    or

    loop at itab2.

    read table itab1 with key f1 = itab2-f1.

    if sy-subrc <> 0.

    delete itab2.

    endif.

    endloop.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 20, 2006 at 10:10 AM

    loop at itab2.

    read table itab1 with key colum1 = itab2-column1 column2 = column2.

    if sy-subrc = 0.

    delete itab2.

    endif.

    endloop.

    Regards,

    Ravi

    Note : Please mark the helpful answers

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 20, 2006 at 10:36 AM

    HI Kumar,

    Try with following code.

    ITAB1 FIELD1 FIELD2 FIELD3 FIELD4

    1stIT A B C D

    ITAB2 FIELD1 FIELD2 FIELD3 FIELD4 FIELD5 FIELD6 FIELD7

    2ndIT A B C D E F G

    <b>LOOP AT ITAB1.

    READ TABLE ITAB2 WITH KEY FIELD1 = ITAB1-FIELD1 FIELD2 = ITAB1-FIELD2 FIELD3 = ITAB1-FIELD3 FIELD4 = ITAB1-FIELD4.

    IF SY-SUBRC <> 0.

    DELETE ITAB2.

    ENDIF.

    ENDLOOP.</b>

    Thanks,

    Vinay

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 20, 2006 at 11:01 AM

    Hi pavan,

    Please check this code.

    loop at tab1.

    read table tab2 with key field1 = tab1-field1.

    if sy-subrc ne 0.

    delete tab2.

    modify tab2.

    endif.

    endloop.

    Hope this will help u.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 20, 2006 at 11:14 AM

    Hi pavan,

    I hope this works for ur criteria...

    Loop at itab1.

    Delete Itab2 where field_1 <> itab1-field_1

    and field_2 <> itab1-field_2

    and field_3 <> itab1-field_3

    Endloop.

    regards,

    Kiran B

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 20, 2006 at 11:26 AM

    Hi,

    try this,,

    sort: it1 , it2 ,

    loop at it1.

    read table it2 with key pernr = it1-pernr

    FAC_C = it1-FAC_C

    binary search.

    if sy-subrc eq 0.

    write: / it1-pernr, it1-fac_c.

    endif.

    endloop.

    or

    User Corresponding field option

    or

    if it1[] = it2[].

    If it helps reward points

    Regards,

    Nandha

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 20, 2006 at 10:10 AM

    Hi

    LOOP AT ITAB2.

    READ TABLE ITAB1 WITH KEY FIELD = ITAB2-FIELD.

    IF SY-SUBRC <> 0. DELETE ITAB2. ENDIF.

    ENDLOOP.

    max

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 20, 2006 at 10:13 AM

    Sort internal table 1 by A B C D.

    Now ..

    copy contents of 2nd table to a temp table.

    loop at 2nd internal table.

    read 1st internal table with key a = 2internal table a

    b = 2internal table b

    c = 2internal table c

    d = 2internal table d.

    if sy-subrc ne 0.

    delete entry from temp table.

    now refresh table 2.

    copy contents of temp to table 2.

    Guys,

    I guess DELETING THE SAME TABLE WITHIN A LOOP .. ENDLOOP is not advisable.Please correct me if i m wrong.

    endif.

    endloop.

    Message was edited by: Nishanth Bhandar

    Message was edited by: Nishanth Bhandar

    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.