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

Get the Common from Two Internal Tables with same structure

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

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 Oct 17, 2006 at 08:53 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 17, 2006 at 08:58 AM

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

    Something like ITAB1 IN ITAB2 etc...

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 17, 2006 at 08:51 AM

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

    Regards,

    Ravi

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 17, 2006 at 08:52 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 17, 2006 at 08:52 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 17, 2006 at 08:53 AM

    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

    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.