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

internal table

Hi Guys,

Please help me with the following.

I have 2 internal tables :

1. itab1 ---has data from db1.

2. itab2 ---has data from db2.

Now only few fields of itab1 and itab2 are similar.Depending on this common fields i need to take all the

unique records itab1 and itab2.

Eg1: itab1 has a,b,c

itab2 has a,b,c,d,

result table itab3 shd have a,b,c,d.

Eg2: itab1 has a,b,c

itab2 has a,b

result table itab3 shd have a,b,c

How do i achieve this?

Use meaningful subject for your future questions

Edited by: Vijay Babu Dudla on Jan 15, 2009 4:51 AM

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

11 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jan 15, 2009 at 05:48 AM

    hi sudha

    Try JOINs

    thanks

    Sachin

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 15, 2009 at 06:00 AM

    This message was moderated.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 15, 2009 at 06:00 AM

    try this

    Instead of reading data into internal table u can directly apply joins in the database table , because you cannot write join on internal table

    SELECT sa sb sc pd

    INTO CORRESPONDING FIELDS OF TABLE itab

    FROM db1 AS s

    INNER JOIN db2 AS p

    ON sa = pa AND

    sb = pb.

    This will solve your problem

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 15, 2009 at 06:04 AM

    Hello

    itab3[] = itab1[].
    loop at itab2.
      read table itab3 with key field = itab2-field.
      if sy-subrc NE 0.
        clear itab3.
        move-corresponding itab2 to itab3.
        append itab3.
      endif.
    endloop.
    

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 15, 2009 at 06:24 AM

    Hi ,

    Joins are best if there is a requirement to fetch data from multiple takles based on common fields.

    Refer this link for details:

    http://www.thespot4sap.com/Articles/SAPABAPPerformanceTuning_InnerJoinStatement.asp

    Regards,

    Radhika.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 15, 2009 at 06:26 AM

    Hi,

    use the move atatement

    Move and equal are one and the same

    if u go for move corresponding

    move-corresponding means if two structures having few different components and few are with same names then this move the values from one structure to another structure where the name are same.

    regards,

    Madhu

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 15, 2009 at 06:33 AM

    Hi ,

    Joins are used in the retrieval of data from data base tables itself.

    So you can move the common records to a single internal table based on the required condition.

    Also you can refer this link for a complete description

    http://help.sap.com/saphelp_nw04/helpdata/EN/fc/eb39c4358411d1829f0000e829fbfe/frameset.htm

    Regards,

    Radhika.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 15, 2009 at 06:51 AM

    Hi Sudha,

    For Eg1: itab1 has a,b,c

    itab2 has a,b,c,d,

    you can try the following:

    itab3: int table of structure a,b,c,d

    wa_tab3: work area of structure a,b,c,d

    MOVE itab2 TO itab3. "All the entries in tab2 are moved to final
    
    LOOP AT itab1 INTO wa_tab1.
      READ TABLE itab2 INTO wa_tab2 key
      a = wa_tab1-a  b = wa_tab1-b c = wa_tab1-c.
        "If it is not a common entry move to final table
      IF sy-subrc NE 0.
        MOVE-CORRESPONDING wa_tab1 TO wa_tab3.
        APPEND wa_tab3 TO itab3.
      ENDIF.
    ENDLOOP.

    Hope this helps you.

    Regards,

    Manoj Kumar P

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 15, 2009 at 07:07 AM

    Hi Subha,

    Try to do it this way:

    Loop at itab1 into wa1.
    
      Read table itab2 into wa2 with key field1 eq wa-field1.
      If sy-subrc eq 0.
        Delete table itab2 from wa2.
      Endif.
      wa3 = wa1.
      Append wa3 to itab3.
    Endloop.
    
    Loop at itab2 into wa2.
      wa3 = wa2.
      Append wa3 to itab3.
    Endloop.

    With luck,

    Pritam.

    Edited by: Pritam Ghosh on Jan 15, 2009 8:29 AM

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 15, 2009 at 07:27 AM

    Hi,

    If the two tables are database tables then u can use JOIN in SELECT statement.

    Otherwise you are using internal tables then the following code will help u.

    loop at itab2 into wa_itab2.

    read table itab1 into wa_itab1 with key a = wa_itab2-a

    b = wa_itab2-b c = wa_itab2-c.

    if sy-subrc eq 0.

    move: wa_itab2-a to wa_itab3-a,

    wa_itab2-b to wa_itab3-b,

    wa_itab2-c to wa_itab3-c,

    wa_itab2-d to wa_itab3-d.

    append wa_itab3 to itab3.

    endif.

    endloop.

    Hope this will help u.

    Thanks.

    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.