Regarding joining two internal tables

Hi All,
Tell me how to use 'UNION' in different ways.
Thank you,
Rohit

Hi,
If its internal table joining then best is to use APPEND LINES.... statement.
You can also append internal tables to index tables using the following statement:
APPEND LINES OF itab1 TO itab2.
This statement appends the whole of ITAB1 to ITAB2. ITAB1 can be any type of table, but its line type must be convertible into the line type of ITAB2.
When you append an index table to another index table, you can specify the lines to be appended as follows:
APPEND LINES OF itab1 [FROM n1] [TO n2] TO itab2.
n1 and n2 specify the indexes of the first and last lines of ITAB1 that you want to append to ITAB2.
This method of appending lines of one table to another is about 3 to 4 times faster than appending them line by line in a loop. After the APPEND statement, the system field SY-TABIX
contains the index of the last line appended. When you append several lines to a sorted table, you must respect the unique key (if defined), and not violate the sort order. Otherwise, a runtime error will occur.
thanx.

Similar Messages

  • How to join two internal table rows in alternative manner into one internal table?

    How to join two internal table rows in alternative manner into one internal table?
    two internal tables are suppose itab1 &  itab2 & its data
    Header 1
    Header 2
    Header 3
    a
    b
    c
    d
    e
    f
    g
    h
    i
    Header 1
    Header 2
    Header 3
    1
    2
    3
    4
    5
    6
    7
    8
    9
    INTO itab3 data
    Header 1
    Header 2
    Header 3
    a
    b
    c
    1
    2
    3
    d
    e
    f
    4
    5
    6
    g
    h
    i
    7
    8
    9

    Hi Soubhik,
    I have added two additional columns for each internal table.
    Table_Count - It represents the Internal Table Number(ITAB1 -> 1, ITAB2 -> 2)
    Row_Count  - It represents the Row Count Number, increase the row count value 1 by one..
    ITAB1:
    Header 1
    Header 2
    Header 3
    Table_Count
    Row_Count
    a
    b
    c
    1
    1
    d
    e
    f
    1
    2
    g
    h
    i
    1
    3
    ITAB2:
    Header 1
    Header 2
    Header 3
    Table_Count
    Row_Count
    1
    2
    3
    2
    1
    4
    5
    6
    2
    2
    7
    8
    9
    2
    3
    Create the Final Internal table as same as the ITAB1/ITAB2 structure.
    "Data Declarations
    DATA: IT_FINAL LIKE TABLE OF ITAB1.          "Final Internal Table
    FIELD-SYMBOLS: <FS_TAB1> TYPE TY_TAB1,     "TAB1
                                   <FS_TAB2> TYPE TY_TAB2.     "TAB2
    "Assign the values for the additional two column for ITAB1
    LOOP AT ITAB1 ASSIGNING <FS_TAB1>.
         <FS_TAB1>-TABLE_COUNT = 1.             "Table value same for all row
         <FS_TAB1>-ROW_COUNT = SY-TABIX. "Index value
    ENDLOOP.
    "Assign the values for the additional two column for ITAB2
    LOOP AT ITAB2 ASSIGNING <FS_TAB2>.    
         <FS_TAB2>-TABLE_COUNT = 2.                  "Table value same for all row
         <FS_TAB2>-ROW_COUNT = SY-TABIX.      "Index value
    ENDLOOP.
    "Copy the First Internal Table 'ITAB1' to Final Table
    IT_FINAL[] = ITAB1[].
    "Copy the Second Internal Table 'ITAB2' to Final Table
    APPEND IT
    LOOP AT ITAB2 INTO WA_TAB2.
    APPEND WA_TAB2 TO IT_FINAL.
    ENDLOOP.
    "Sort the Internal Table based on TABLE_COUNT & ROW_COUNT
    SORT IT_FINAL BY  ROW_COUNT TABLE_COUNT.
    After sorting, check the output for IT_FINAL Table, you can find the required output as shown above.
    Regards
    Rajkumar Narasimman

  • Joining Two Internal Tables - ( Urgent )

    Could anybody please give me the whole code for joining two internal tables
    and putting the data in a third internal table. Please, very urgent.
                                                                                    Regards,
                                                                                    SAURAV

    Hi,
      Refer this code
    *&      Form  SUB_READ_VBRK
          text
    FORM sub_read_vbrk.
      SELECT vbeln
             rplnr
             bukrs
             FROM vbrk
             INTO TABLE it_vbrk
             WHERE vbeln IN s_vbeln
             AND   rplnr NE ' '.
      IF sy-subrc EQ 0.
        SORT it_vbrk BY rplnr.
      ENDIF.
    ENDFORM.                    " SUB_READ_VBRK
    *&      Form  SUB_READ_FPLTC
          text
    FORM sub_read_fpltc.
      IF NOT it_vbrk[] IS INITIAL.
        SELECT fplnr
               fpltr
               ccnum
               FROM fpltc
               INTO TABLE it_fpltc
               FOR ALL ENTRIES IN it_vbrk
               WHERE fplnr EQ it_vbrk-rplnr
               AND   ccins EQ 'GIFC'.
        IF sy-subrc EQ 0.
          SORT it_fpltc BY fplnr.
        ENDIF.
      ENDIF.
    ENDFORM.                    " SUB_READ_FPLTC
    *&      Form  SUB_COLLECT_DATA
          text
    FORM sub_collect_data.
    *--Local variables
      DATA : lv_count(3) TYPE c.
      IF NOT it_fpltc[] IS INITIAL.
        LOOP AT it_fpltc INTO wa_fpltc.
          lv_count = wa_fpltc-fpltr+3(3).
          wa_final-ccnum = wa_fpltc-ccnum.
          wa_final-rfzei = lv_count.
          CLEAR : wa_vbrk.
          READ TABLE it_vbrk INTO wa_vbrk WITH KEY rplnr = wa_fpltc-fplnr
                                                   BINARY SEARCH.
          IF sy-subrc EQ 0.
            wa_final-vbeln = wa_vbrk-vbeln.
            wa_final-bukrs = wa_vbrk-bukrs.
          ENDIF.
          APPEND wa_final TO it_final.
          CLEAR : wa_vbrk,
                  wa_fpltc,
                  lv_count.
        ENDLOOP.
      ENDIF.
    ENDFORM.                    " SUB_COLLECT_DATA
    Regards,
    prashant

  • Regarding Passing two internal Tables from Driver Program to Smartform

    hi all,
              I am Passing Two Internal Tables from Driver Program to Smartform it is going to dump and message is showing like this " one of the parameters eded according to the interface description was not specified ".
              When i am passing one Internal Table Output is coming Perfectly. Is there any restriction for passing of internal tables.
    Regards
    Rami

    HI,
    Check the names specified in the smartfrom and FM whcih you are calling in the driver program. Both might be different....

  • Can we join two internal tables

    Hi to all,
    i want take data from one database(db) table into internal table from this we want to retrieve data from other db table and put this data into another internal table .provided that two db tables are depends on foreign key relations .

    You can do this a number of ways.  You can use an inner join in your select statement and put the required data into an internal table or you can do two selects from the db and loop at the first itab,  then loop at the second where the keys match and put the required data into a third internal table.
    Here is an example of using an inner joine to get data from db tables into one internal table.
    report zrich_0001.
    data: begin of ima occurs 0,
          matnr type mara-matnr,
          mtart type mara-mtart,
          werks type marc-werks,
          dispo type marc-werks,
          end  of ima.
    select-options: s_matnr for ima-matnr.
    select mara~matnr mara~mtart marc~werks marc~dispo
           into table ima
                 from mara
                     inner join marc
                         on mara~matnr = marc~matnr
                                 where mara~matnr in s_matnr.
    loop at ima.
      write:/ ima-matnr, ima-mtart, ima-werks, ima-dispo.
    endloop.
    Regards,
    Rich Heilman

  • Joining two internal table

    Hi expert,
                  I'm using 'Reuse_Alv_Hierseq_List_Display' and i wanted to joing the header data(vbak & kna1) and item data (vbap & vbep) seperately.So that i could assign this internal table name in the about funtion module parameters(I_OUTTAB_HEADER & I_OUTTAB_ITEM).Plz help me out!
    Regards,
    Arshad.

    Using I Joins decreses the performance.
    U can use FOR ALL ENTRIES instead.
    1st fetch required data from VBAK
    Then fetch data from KNA! for all entries of VBAK
    2ndt fetch required data from VBAP
    Then fetch data from VBEP for all entries of VBAP
    Reward if useful

  • Join two internal tables

    hi all
        please give a query for joining of three internal tables and store into another table,and we should retrive data from that third table
    please take those fields as material number,plant,storage location,stock,units

    Hello Raja,
    SELECT EKKNEBELN EKKNEBELP EKKNKOSTL EKKNPS_PSP_PNR EKKN~SAKTO
          EKETWEMNG EKETETENR EKETBEDAT EKPOKNTTP EKPOLOEKZ EKPOMATNR
          EKPOWERKS EKPOMATKL  EKPOMENGE EKPOMEINS EKPONETPR EKPOPEINH
          EKPONETWR EKPOMTART EKPOEFFWR EKKOBUKRS EKKOBSART EKKOERNAM
          EKKOLIFNR EKKOEKORG EKKOEKGRP EKKOWAERS EKKO~BEDAT
          EKKO~MEMORY INTO TABLE G_T_OUTTAB
       FROM ( EKKN
               INNER JOIN EKET
               ON EKETEBELN = EKKNEBELN
               AND EKETEBELP = EKKNEBELP
               INNER JOIN EKPO
               ON EKPOEBELN = EKETEBELN
               AND EKPOEBELP = EKETEBELP
               INNER JOIN EKKO
               ON EKKOEBELN = EKPOEBELN )
             WHERE EKKN~EBELN IN S_EBELN
               AND EKKN~EBELP IN S_EBELP
               AND EKKN~KOSTL IN S_KOSTL
               AND EKKN~PS_PSP_PNR IN S_WBS
               AND EKKN~SAKTO IN S_SAKTO
               AND EKPO~KNTTP IN S_KNTTP
               AND EKPO~LOEKZ IN S_LOEKZ
               AND EKPO~MATKL IN S_MATKL
               AND EKPO~MATNR IN S_MATNR
               AND EKPO~WERKS IN S_WERKS
               AND EKKO~BEDAT IN S_BEDAT
               AND EKKO~BSART IN S_BSART
               AND EKKO~BUKRS IN S_BUKRS
               AND EKKO~EKGRP IN S_EKGRP
               AND EKKO~EKORG IN S_EKORG
               AND EKKO~ERNAM IN S_ERNAM
               AND EKKO~LIFNR IN S_LIFNR
               AND EKPO~MTART IN S_MTART
               AND EKKO~MEMORY IN S_MEMORY
               AND EKET~BEDAT IN S_DAT_ET.
    Try with this code.
    If useful reward.
    Vasanth

  • Joining of two internal tables...... urgent.

    Dear all experts,
    I am going to join two internal tables, one table contains some fields from mara
    and another table contains some fields from makt.
    i have to join these tables without using for all entries.
    below is program mentioned... I am not getting exactly how to put the logic, to get fields into table itab_3.
    <b>*------- defining internal tables.</b>
    DATA: BEGIN OF <b>itab_1</b> OCCURS 0,
            matnr  TYPE mara-matnr,
          END OF itab_1.
    DATA: BEGIN OF <b>itab_2</b> OCCURS 0,
            matnr  TYPE makt-matnr,
            maktx  TYPE makt-maktx,
            spras  TYPE makt-spras,
          END OF itab_2.
    DATA: BEGIN OF <b>itab_3</b> OCCURS 0,
            matnr TYPE mara-matnr,
            spras TYPE makt-spras,
          END OF itab_3.
    <b>*---taking data to first internal table.-</b>
    SELECT matnr
                 FROM mara
                 INTO TABLE itab_1
                 WHERE ernam = 'RUDISILL'.
    <b>*--taking data to second internal table.--</b>
    SELECT matnr maktx spras
           FROM makt
           INTO TABLE itab_2.
    sort itab_1 by matnr.
    sort itab_2 by matnr.
    can anybody please tell, how to take fields of itab_2 to itab_3, where all matnr in itab_2  should be equal to all matnr in itab_1.
    points will be surely assigned to your help.
    waiting
    Warm regards
    Vinay.

    hi,
    kindly chk this sample.
    check this.
    data : begin of itab1 occurs 0. "itab with work area.
    key_field1 like ztable1-key_field1,
    field1 like ztable1-field1,
    field2 like ztable1-field2,
    endof itab1.
    data : begin of itab2 occurs 0. "itab with work area.
    key_field2 like ztable2-key_field2,
    field3 like ztable2-field3,
    field4 like ztable2-field4,
    endof itab2.
    data : begin of itab_final occurs 0.
    key_field1 like ztable1-key_field1,
    field1 like ztable1-field1,
    field2 like ztable1-field2,
    field3 like ztable2-field3,
    field4 like ztable2-field4,
    endof itab_final.
    put the date final(merged) internal table
    1. loop at itab1.
    read table itab2 with key keyfield2 = itab1-keyfield1.
    if sy-surc = 0.
    itab_final-key_field1 = itab1-keyfield1
    itab_final-field1 = itab1-field1.
    itab_final-field2 = itab1-keyfield2.
    itab_final-field3 = itab2-field2.
    itab_final-field4 = itab2-keyfield2.
    append itab_final.
    clear itab_final.
    endif.
    endloop.
    or
    LOOP AT ITAB1.
    MOVE-CORRESPONDING TO ITAB1 to ITAB_FINAL.
    READ TABLE ITAB2 WITH KEY FILED1 = ITAB1-FIELD1.
    if sy-subrc = 0.
    MOVE-CORRESPONDING TO ITAB2 to ITAB_FINAL.
    endif,
    READ TABLE ITAB3 WITH KEY FILED1 = ITAB1-FIELD1.
    if sy-subrc = 0.
    MOVE-CORRESPONDING TO ITAB2 to ITAB_FINAL.
    endif,
    append itab_final.
    clear itab_final.
    endloop
    Regards,
    Anversha

  • Join the two internal table

    Hi Guys,
    I have two internal tables with same structure, ITAB1 is having 100 records and ITAB2 is having 150 records, i need to club two internal tables into ITAB3.
    I hope, we can loop one internal table append record by record.
    Is any other way, can we club two internal tables.
    Thanks,
    Gourisankar.

    Hi,
    You can use INSERT LNES OF ITAB1 INTO ITAB3 and afterwards do the same with ITAB2.
    Regards, Gerd Rother

  • Can we join two totals tables in ABAP Query

    Hey Gurus!
    Can we join two totals tables in ABAP query.
    I am tyring to join FAGFLEXT with internal orders totals table.
    Thanks
    S

    Hi,
    Report painter majorily operates around characteristics and key figures.
    ABAP query comes even more handy.  The advantage is -
    1. You can link many tables
    2. Create selection screen as you like to have
    3. User friendly report creation
    4.  Logic can also be coded.
    5. Authorization can be set
    I have written a article in SDN, which gives you an idea as to how to go about using ABAP query.  Have a look on this - [Article - Practical Usage of ABAP Query|https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/20f6b256-23be-2b10-8b93-cad83a617634]
    Regards,
    Sridevi

  • Using for all entries of two internal tables in where clause of the select

    Hi experts,
    My requirement is, need to select Marc-minbe and wrpl-sobst, for all the entries of the two internal tables it_mara , and it_t001w.
    here is the select queries i have used,
    select matnr normt from  mara into it_mara for all entries in it_data where normt = it_data-normt.
    select konnr werks from t001w into it_t001w for all entries in it_data where konnr = it_data-konnr.
    now i need to select minbe of marc table and sobse of wrpl table for all the entries of above internal tables, it_mara and it_t001w, using both matnr of it_mara and werks of it_t001w in where condition.
    Pls advise how i can do it.
    Thanks.
    Moderator message: very basic, please work on this yourself first, these forums are not a substitute for ABAP training.
    Edited by: Thomas Zloch on Dec 6, 2010 9:38 AM

    Hi
    call SE16 with table TFTIT in order to get a full list (it will be long...)
    A list of FMs with parameters can be found in table FUNCT.
    Finally go to sm37rsdf4
    that will give you all the function modules with description
    Here is the list:
    http://www.erpgenie.com/abap/functions.htm
    hope this helps...
    Regards
    CSM Reddy

  • Comparing each value of two internal tables

    HI  everybody,
    i have two internal tables  itab1 and itab2 same structure
    both r having four fields each and field with values
    now i need to compare the two internal tables
    and if every value of itab1 matches itab2
    then i have to write one select quirie  for the following given description
    compare past and current shipping point
    compare internal_table2 and internal_table3
    if entry in internal_table2 and internal table3 match
    variable_tknum = internal_table2-tknum
    endif.
    for each entry that matches:
    select vlabdata into zi_vlabdata from vlbl where vbeln = variable_tknum and vlbl-vlabtyp = 'ZIBOOKNO'.
    plz give me solution for this
    thanks
    hridhayanjili.

    sort : ITAB1 by f1,f2,f3,f4,
           ITAB2 by f1,f2,f3,f4.
    LOOP AT ITAB1.
      READ TABLE ITAB2 WITH KEY F1 = ITAB1-F1
                                F2 = ITAB1-F2
                                F3 = ITAB1-F3
                                F4 = ITAB1-F4 BINARY SEARCH.
      IF SY-SUBRC = 0.
    *--all the fields of ITAB1 and ITAB2 are matching .
    *--write your logic here
      ELSE.
    *--ITAB1 and ITAB2 records are not matching.
      ENDIF.
    ENDLOOP.
    Regards
    Srikanth
    Message was edited by: Srikanth Kidambi

  • Reg  comparison of two  internal tables

    hi friends,
    please help me solving this.
    there are two internal tables t_zvs38 and t_value
    1.t_value like seahlpres
    2.t_zvs38 like zvs38.
    values in t_value will be like this.
    first line wil contain zmdtype(mandatory document) and second line will contain
    zmdtypet (the description for zmdtype).
    eg.
    D001 -
    -zmdtype
    internal----
    zmdtypet
    D002
    external
    D003
    renewal
    values in t_zvs38.
    for a particular sales.org the zmdtype is filled.
    select vkorg zmdtype into corrsponding fields of table t_zvs38
    where vkorg = p_vkorg.
    Now i want to compare t_value and t_zvs38 with field zmdtype
    and delete the contents of  t_value which are not in t_zvs38.
    i have written like this.
    loop at t_value.
    read table t_zvs38 with key zmdtype = t_value-string.
    if sy-subrc ne 0.
    delete t_value. "to delete zmdtype
    sy-tabix = sy-tabix + 1.
      delete t_value. " to delete zmdtypet
    else.
    sy-tabix = sy-tabix +2. "to go to next zmdtype.
    endif.
    endloop.
    but it is deleting all the contents of t_value.
    points are assured.

    CLEAR zvs32t.
      SELECT zvs32tzmdtype zvs32tzmdtypet
        INTO (zvs32t-zmdtype, zvs32t-zmdtypet)
        FROM zvs32t
        JOIN zvs32
        ON   zvs32tzmdtype = zvs32zmdtype
        WHERE zvs32t~spras    = sy-langu
        AND   zvs32~zfrenewal = space.
         WRITE zvs32t-zmdtype TO t_value.
        APPEND t_value.
        WRITE zvs32t-zmdtypet TO t_value.
        APPEND t_value.
      ENDSELECT.
      SELECT vkorg vkbur zmdtype FROM zvs38 INTO CORRESPONDING FIELDS OF TABLE t_zvs38
      WHERE vkorg = p_vkorg
    AND vkbur = p_vkbur.
      LOOP AT t_value INTO wa_area1.
        v_index = sy-tabix.
        READ TABLE t_zvs38 INTO wa_area2 WITH KEY zmdtype = wa_area1-string
      BINARY SEARCH.
       IF sy-subrc NE 0.
          IF l_flag IS INITIAL.
            DELETE t_value INDEX v_index.
           ELSE.
            CLEAR l_flag.
          ENDIF.
       ELSE.
          l_flag = 'X'.
       ENDIF.
      ENDLOOP.
    Using this code ,i am unable to ge the correct output.Thank u all for ur help.

  • Two internal tables in to one internal table

    Hi , 
               I have two internal tables ITAB1 and ITAB2, i would like to put fields from  two internal tables in to one internal table(ITAB3) with out using inner joint. any one of you can give the sample code for this
    Thanks
    Raja.

    Hi,
    Kamesh wrote :
          Read itab2 into wa_itab2 with key f2 = itab1-f1 <USe your where conditions here>.
    Read statement does not have WHERE conditions.
    Please be careful while posting. Your thread will be reffered by many people. Please dont mislead.
    Regards,
    Swapna.

  • 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

    Hi
    call SE16 with table TFTIT in order to get a full list (it will be long...)
    A list of FMs with parameters can be found in table FUNCT.
    Finally go to sm37rsdf4
    that will give you all the function modules with description
    Here is the list:
    http://www.erpgenie.com/abap/functions.htm
    hope this helps...
    Regards
    CSM Reddy

Maybe you are looking for

  • Many many problems after 10.5.8 update

    Used software update to install 10.5.8 after having been in 10.5.7. Since then: 1: Firefox beachballs constantly, then after force quitting, which takes forever I can't open the application. I click the icon in the dock and nothing happens. I open th

  • External webcams -- do any work with built-in isight?

    I have an intel Macbook with the built-in isight camera. I'd like to be able to use an external web cam -- but I can't get any to work -- the machine simply ignores them. Can anyone tell me which, if any, external cams have worked with this setup? An

  • How to log when a menu option is selected in an IVR Script

    Our business would like to track how many customers select a specific option in the menu of a CCX script.  For example: Customer calls in to the IVR and selects option 2 for a password reset within the menu.  My question is how to configure this with

  • Saving my iPhoto to a external HD

    Hello! I have a MacBok Pro and use iPhoto 08, my problem is my iPhoto Lib is reaching 92GB! So I want to store my photos on a portable HD. Is there an easy way to do it? I understand that I will have to take the portable HD with me every where I go i

  • Adobe Lightroom3 won't print after Security and Airport updates.

    10.6.7 8gb Mac Mini intel... using epson 2400 and other printers, the print job does not show up in the printer que- printers work in other apps like photoshop.... deleted and added the 2400 to the printer and fax in system prefs....