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

join 2 internal tables into 1 internal table

itab 1

-


field 1

1

2

3

5

itab2

-


field 1

1

2

3

4

6

The result require is

itab3

-


filed 1

1

2

3

4

5

6

how to achieve this if any one can give the exact code for this it will be of great help to me.

thanks

naveen

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

9 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Nov 19, 2007 at 12:36 PM

    Hi Naveen,

    Loop through both the internal tables seperately and append data to itab3.

    sort itab3 by field1.

    delete adjucent duplicates from itab3 comparing field1.

    Reward Points if this helps,

    Satish

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 19, 2007 at 12:48 PM

    HI Naveen,

    you can use like this ....

    loop at itab1.

    loop at itab2 where field1 = itab1-field1.

    itab3-field1 = itab1-field1.

    itab3-field2 = itab1-field2.

    itab3-field3 = itab1-field3.

    itab3-field4 = itab1-field4.

    itab3-field5 = itab1-field5.

    itab3-field6 = itab2-field6.

    append itab3.

    endloop.

    endloop.

    Reward if usefull.

    Thanks,

    Gokul

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 19, 2007 at 12:59 PM

    Hi

    SORT it_b BY vkorg.

    LOOP AT it_a.

    READ TABLE it_b WITH KEY vkorg = it_a-vkorg

    BINARY SEARCH

    TRANSPORTING NO FIELDS.

    IF sy-subrc EQ 0.

    • Display MATNR - SALES ORG - DCHANNEL - STATUS - DESCRIPTION

    ENDIF.

    ENDLOOP.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 19, 2007 at 03:21 PM

    Hi Naveen,

    Try something like this,

    sort itab2 by field1 ascending.
    Loop at itab1 into lw_tab1.
    read table itab2 into lw_tab2 with key field1 = lw_tab1-field1 binary search.
    if sy-subrc NE 0.
    lw_tab2-field1 = lw_tab3-field1.
    append lw_tab3 to i_tab3.
    clear : lw_tab3,lw_tab2.
    else.
    lw_tab3-field1 = lw_tab1.
    append lw_tab3 to i_tab3.
    clear lw_tab3.
    endif.
    clear lw_tab1.
    endloop.
    sort i_tab3 by field1

    If works reward points.

    Regards,

    Bharathy.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 19, 2007 at 07:28 PM

    see below cod

    itab3[] = itab1[].

    loop at itab2.

    append itab2 to itab3.

    endlooop.

    sort itab3 by field1.

    delete adajcent duplicates of itab3 by comparing field1.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 20, 2007 at 08:26 AM

    ITAB3 = ITAB1.

    LOOP AT ITAB1 INTO WA.

    READ TABLE ITAB2 WITH KEY FIELD1 = WA-FIELD1 INTO WA2.

    IF SY-SUBRC NE 0.

    APPEND WA TO ITAB3.

    ENDIF.

    ENDLOOP.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 20, 2007 at 12:59 PM

    hi ,

    create the new internal table with all required fields and select the data from those tables through inner-join query as example follows.

    REPORT Z0292_INT_SELECT.

    DATA : BEGIN OF WA,

    PONO TYPE Z0292_PURITEM-PONO,

    ITEM TYPE Z0292_PURITEM-ITEM,

    POD TYPE Z0292_PURHEA-POD,

    VENID TYPE Z0292_PURHEA-VENID,

    END OF WA.

    DATA : ITAB LIKE TABLE OF WA WITH HEADER LINE.

    SELECT APONO AITEM BPOD BVENID

    INTO TABLE ITAB

    FROM Z0292_PURITEM AS A INNER JOIN Z0292_PURHEA AS B

    ON APONO = BPONO.

    LOOP AT ITAB.

    WRITE : / ITAB-PONO,ITAB-ITEM,ITAB-POD,ITAB-VENID.

    ENDLOOP.

    sagun desai

    Posts: 51

    Questions: 9

    Registered: 2/27/06

    Forum points: 48

    Re: how to get the data in one internal table? with 3 different tables..

    Posted: Jul 31, 2007 10:34 AM in response to: rhymmeanne Reply E-mail this post

    DATA : BEGIN OF IT_A005 OCCURS 0,

    vkorg TYPE a005-vkorg,

    vtweg TYPE a005-vtweg,

    kschl TYPE a005-kschl,

    matnr TYPE a005-matnr,

    kunnr TYPE a005-kunnr,

    datab TYPE a005-datab,

    end of it_a005.

    DATA : begin of IT_MVKE OCCURS 0,

    matnr TYPE MVKE-matnr,

    vkorg TYPE MVKE-vkorg,

    vtweg TYPE MVKE-vtweg,

    kondm TYPE mvke-kondm,

    end of it_mvke.

    DATA : begin of IT_KNVV OCCURS 0,

    kunnr TYPE KNVV-kunnr,

    vkorg TYPE KNVV-vkorg,

    vtweg TYPE KNVV-vtweg,

    kdgrp TYPE knvv-kdgrp,

    konda TYPE knvv-konda,

    end of it_knvv.

    DATA : BEGIN OF IT_FINAL OCCURS 0,

    vkorg TYPE a005-vkorg,

    vtweg TYPE a005-vtweg,

    kschl TYPE a005-kschl,

    kondm TYPE mvke-kondm,

    matnr TYPE a005-matnr,

    kdgrp TYPE knvv-kdgrp,

    konda TYPE knvv-konda,

    kunnr TYPE a005-kunnr,

    datab TYPE a005-datab,

    END OF IT_FINAL.

    SELECT * FROM A005 INTO TABLE IT_A005.

    SELECT * FROM MVKE INTO CORRESPONDING FIELDS

    OF TABLE IT_MVKE

    FOR ALL ENTRIES IN IT_A005

    WHERE MATNR = IT_A005-MATNR

    AND VKORG = IT_A005-VKORG

    AND VTWEG = IT_A005-VTWEG.

    SELECT * FROM KNVV INTO CORRESPONDING FIELDS

    OF TABLE IT_KNVV

    FOR ALL ENTRIES IN IT_A005

    WHERE KUNNR = IT_A005-KUNNR

    AND VKORG = IT_A005-VKORG

    AND VTWEG = IT_A005-VTWEG.

    LOOP AT IT_A005.

    IT_FINAL-vkorg = IT_a005-vkorg.

    IT_FINAL-vtweg = IT_a005-vtweg.

    IT_FINAL-kschl = IT_a005-kschl.

    IT_FINAL-MATNR = IT_a005-matnr.

    IT_FINAL-KUNNR = IT_a005-kunnr.

    IT_FINAL-DATAB = IT_a005-datab.

    READ TABLE IT_MVKE WITH KEY MATNR = IT_A005-MATNR

    AND VKORG = IT_A005-VKORG

    AND VTWEG = IT_A005-VTWEG.

    IT_FINAL-kondm = IT_mvke-kondm.

    READ TABLE IT_KNVV WITH KEY KUNNR = IT_A005-KUNNR

    AND VKORG = IT_A005-VKORG

    AND VTWEG = IT_A005-VTWEG.

    IT_FINAL-kdgrp = IT_knvv-kdgrp.

    IT_FINAL-konda = IT_knvv-konda.

    APPEND IT_FINAL.

    CLEAR : IT_FINAL, IT_MVKE, IT_KNVV.

    ENDLOOP.

    You can try with this code.

    It should work.

    if it ok for you then you can close this issue.

    Cheers,

    Sagun Desai.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 20, 2007 at 01:21 PM

    THANKS

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 20, 2007 at 01:22 PM

    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.