Merge 2 internal table

hi,
1st internal table contains 5 field from ekko - po header table
2nd internal table contains corresponding value from ekpo - po line item table.
now i want to merge this table into 3rd table.
please give me best suggestions with minimum loop logic.
thanks,
raj

hi,
plz refer the code below. in this way you can solve your query.
TYPES: begin of itype,
lifnr TYPE rbkp-lifnr,
belnr TYPE rbkp-belnr,
xblnr TYPE rbkp-xblnr,
END OF itype.
TYPES:BEGIN OF itype1,
name1 TYPE lfa1-name1,
END OF itype1.
TYPES: BEGIN OF itype2,
ebeln TYPE ekbe-ebeln,
belnr type ekbe-belnr,
END OF itype2.
DATA: itab TYPE TABLE OF itype, "internal table
wtab TYPE itype. "work area
DATA: itab1 TYPE TABLE OF itype1, "internal table
wtab1 TYPE itype1. "work area
DATA: itab2 TYPE TABLE OF itype2, "internal table
wtab2 TYPE itype2. "work area
select ebeln belnr from ekbe into table itab2 where ebeln in s_ebeln.
SELECT lifnr belnr xblnr FROM rbkp INTO TABLE itab FOR ALL ENTRIES IN
itab2 WHERE
belnr = itab2-belnr.
SELECT name1 FROM lfa1 INTO TABLE itab1 FOR ALL ENTRIES IN itab WHERE
lifnr = itab-lifnr.
Loop at itab2 into wtab2.
iheader-ebeln = wtab2-ebeln.
read table itab into wtab
with key belnr = wtab2-belnr.
iheader-lifnr = wtab-lifnr.
iheader-belnr = wtab-belnr.
iheader-xblnr = wtab-xblnr.
read table itab1 into wtab1
with key lifnr = iheader-lifnr.
iheader-name1 = wtab1-name1.
end loop.
here data of three internal table itab, itab1, itab2 is going in one internal tbale iheader.
regards,
Ruchika
Reward if useful.......

Similar Messages

  • Merging internal table

    Hi,
    I want to add the field names of two internal table to a final table dynamically.
    Please let me know how to do this.
    Thanks & Regards
    Santhosh

    v_repid = sy-repid.
    v_fname = 'ITAB'.      " Your first internal table
    call function 'GET_COMPONENT_LIST'
      exporting
        program    = v_repid
        fieldname  = v_fname
      tables
        components = i_components.
    v_fname = 'ITAB1'.     " Your second internal table 
    call function 'GET_COMPONENT_LIST'
      exporting
        program    = v_repid
        fieldname  = v_fname
      tables
        components = i_components_1.
    " Merge together both internal tables
    append lines of i_components_1 into i_components
    field-symbols:     <fs_table> type table.
    data : i_fieldlist  type table of lvc_s_fcat.
    data : v_ref        type ref to data.
    loop at i_components. 
    i_fieldlist-fieldname = i_components-fielname.
    i_fieldlist-inttype   = i_components-type.
    i_fieldlist-outputlen = i_components-olen.
    append i_fieldlist.
    endloop.
    " internal table build
      call method cl_alv_table_create=>create_dynamic_table
         exporting
           it_fieldcatalog = i_fieldlist
         importing
            ep_table        = v_ref.
      assign v_ref->* to <fs_table>.

  • Help with basic ABAP code (merge internal tables, sort of...)

    Hello,
    Can someone please help write some basic code for a Basis guy with limited ABAP knowledge?
    Should be some easy points for an experienced ABAPer!
    I have identicaly structured internal tables I_A and I_B and I_C which have already been filled by function models I called.
    How will I code the following?:
    I want to read all the data of I_A into a new internal table I_MASTER (structured the same as I_A,I_B and I_C).
    Then I want to read I_B and:
    1)Update I_MASTER with NEW records
    2)Update existing records if the value of field MYFIELD in I_B is smaller than the value of MYFIELD in I_MASTER.
    Then I want to read I_C and:
    1)Update I_MASTER with NEW records
    2)Update existing records if the value of field MYFIELD in I_C is smaller than the value of MYFIELD in I_MASTER.
    Let me know if I can provide anymore information.
    Thanks in advance for you help!
    Adriaan
    Message was edited by: Adriaan
    Message was edited by: Adriaan

    Hi Adriaan ,
    I want to read all the data of I_A into a new internal table I_MASTER (structured the same as I_A,I_B and I_C).
    <b>i_master[] = i_a[] .</b>
    loop at i_b .
    read table i_master with key myfiled < i_b-myfield .
    if sy-subrc = 0 .
    append i_master from i_b .
    endif.
    endloop.
    loop at i_c .
    read table i_master with key myfiled < i_c-myfield .
    if sy-subrc = 0 .
    append i_master from i_c .
    endif.
    endloop.
    Let me know if this helped .
    Regards,
    Varun .
    Message was edited by: varun sonu

  • Merge internal table

    Hi
    I have 5 internal tables. I want to move all the records into single internal table. All 5 internal tables (1 header table and 4 item table) are in different structure. If any one have sample code for this please post the logic for the same.
    Regards
    Ravi

    hi,
    report ztest.
    tables:pa0002,pa0008,pa0021,pa0041.
    data: begin of itab occurs 0,
          pernr like pa0002-pernr,
          vorna like pa0002-vorna,
          nachn like pa0002-nachn,
          end of itab.
    data: begin of itab1 occurs 0,
          pernr like pa0008-pernr,
          begda like pa0008-begda,
          stvor like pa0008-stvor,
          ansal like pa0008-ansal,
          end of itab1.
    data :begin of itab2 occurs 0,
          pernr like pa0021-pernr,
          favor like pa0021-favor,
          fanam like pa0021-fanam,
          end of itab2.
    data:begin of itab3 occurs 0,
         pernr like pa0041-pernr,
         dar01 like pa0041-dar01,
         dat01 like pa0041-dat01,
         end of itab3.
    data:begin of final occurs 0,
          pernr like pa0002-pernr,
          vorna like pa0002-vorna,
          nachn like pa0002-nachn,
          begda like pa0008-begda,
          stvor like pa0008-stvor,
          ansal like pa0008-ansal,
           favor like pa0021-favor,
          fanam like pa0021-fanam,
         dar01 like pa0041-dar01,
         dat01 like pa0041-dat01,
         end of final.
    select-options:s_pernr for pa0002-pernr.
    select pernr
           vorna
           nachn
           from pa0002
           into table itab
           where pernr in s_pernr.
    select pernr
           begda
           stvor
           ansal
           from pa0008
           into table itab1
           for all entries in itab
           where pernr = itab-pernr.
    select pernr
           favor
           fanam
           from pa0021
           into table itab2
           for all entries in itab1
           where pernr = itab1-pernr.
    select pernr
           dar01
           dat01
           from pa0041
           into table itab3
           for all entries in itab2
           where pernr = itab2-pernr.
    loop at itab.
    final-pernr = itab-pernr.
    final-vorna = itab-vorna.
    final-nachn = itab-nachn.
    read table itab1 with key pernr = itab-pernr.
    final-begda = itab1-begda.
    final-stvor = itab1-stvor.
    final-ansal = itab1-ansal.
    read table itab2 with key pernr = itab1-pernr.
    final-favor = itab2-favor.
    final-fanam = itab2-fanam.
    read table itab3 with key pernr = itab2-pernr.
    final-dar01 = itab3-dar01 .
    final-dat01 = itab3-dat01.
    append final.
    clear final.
    endloop.
       loop at final.
       write:final-pernr ,
    final-vorna ,
    final-nachn ,
    final-begda ,
    final-stvor ,
    final-ansal ,
    final-favor ,
    final-fanam ,
    final-dar01 ,
    final-dat01 .
       endloop.
    regards,
    venkat.

  • 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

  • Moving the data of five internal tables to one internal tables.

    iam having the five internal table. like below
    g_t_vbfa
    g_t_vbrk
    g_t_vbpa
    g_t_kna1
    g_t_vbak    
    this are the five internal tables. each tables having the datas . but each table having the number of records is different. one table having 100 records means another table having 50 records.
    previously i used   index sys-tabix  concept it was not working properly...
    my output table is  g_t_output_header_data  ..
    i want to move that output table....
    please coding wise give some solution...
    thanks
    santhosh

    hi,
    chk a sample.
    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
    rgds
    Anver

  • Merging the internal table and structure for PO text material download

    Hi Experts,
       I have a query regarding downloading the PO text from material master.Actually i have successfully downloaded the PO text using TLINE structure along with FM like READ_TEXT and GUI_Download.But when i had to append the PO text for corresponding material,there i got the problem.Let me explain clearly.Below is my coding for PO text download.In that i have used TLINE structure/table for get the POtext via FM READ_TEXT.Also I am using an internal table(It_tab) which consist fields of TDFORMAT,TDLINE and MATNR,So what i need is,i want to merge TLINES structure/table into internal table(it_tab).That is I want to display the PO text along with material No.That is my requirement.But when i append the it_tab using my coding,it was not displaying in the correct order.Attached screen shot is the sample output(excel sheet).column B and C respectively for POtext and material number.I want to get in correct order as it gets the misarrangemnt.(i.e) PO text and material number should come with the same line.So Please help me to complete this task.Kindly point out if i am wrong.
    PO TEXT download from material master :
    DATA :  BEGIN of IT_LINES OCCURS 0.
                INCLUDE STRUCTURE TLINE.
    DATA : END of IT_LINES.
    DATA : t_line TYPE STANDARD TABLE OF IT_LINES WITH HEADER LINE.
    TYPES: BEGIN OF tp_matnr,
            matnr type TDOBNAME,
            END OF tp_matnr.
          DATA:lv_matnr TYPE matnr,
           t_mara TYPE TABLE OF tp_matnr WITH HEADER LINE.
    SELECT-OPTIONS : s_matnr FOR lv_matnr.
    SELECTION-SCREEN BEGIN OF BLOCK BL1 WITH FRAME TITLE TL1.
    PARAMETERS: P_FILE(50) TYPE C.
    *PARAMETERS: P_DOWNL as CHECKBOX.
    SELECTION-SCREEN END OF BLOCK BL1.
    INITIALIZATION.
    TL1 = 'PO TEXT DOWNLOAD'.
    START-OF-SELECTION.
    SELECT matnr FROM mara INTO TABLE t_mara WHERE matnr IN s_matnr.
    DATA : BEGIN OF it_tab OCCURS 0,
             TDFORMAT type TDFORMAT,
             TDLINE type TDLINE,
             MATNR type TDOBNAME,
             END OF it_tab.
    LOOP AT t_mara.
    CALL FUNCTION 'READ_TEXT'
    EXPORTING
    *   CLIENT                        = SY-MANDT
        id                            = 'BEST'
        language                      = 'E'
        name                          = t_mara-matnr
        OBJECT                        = 'MATERIAL'
    *   ARCHIVE_HANDLE                = 0
    *   LOCAL_CAT                     = ' '
    * IMPORTING
    *   HEADER                        =
    *   OLD_LINE_COUNTER              =
       TABLES
        lines                         = t_line
    * EXCEPTIONS
    *   ID                            = 1
    *   LANGUAGE                      = 2
    *   NAME                          = 3
    *   NOT_FOUND                     = 4
    *   OBJECT                        = 5
    *   REFERENCE_CHECK               = 6
    *   WRONG_ACCESS_TO_ARCHIVE       = 7
    *   OTHERS                        = 8
    IF sy-subrc = 0.
         APPEND LINES OF t_line to it_tab.
         it_tab-tdline = t_line-tdline.                                           
         it_tab-matnr = t_mara-matnr.
         APPEND it_tab.
      ENDIF.
      ENDLOOP.
    CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
    FILENAME = 'D:\Test.xls'
    FILETYPE = 'ASC'
    WRITE_FIELD_SEPARATOR = 'X'
    SHOW_TRANSFER_STATUS = 'X'
    TABLES
    DATA_TAB = it_tab

    Hi Manish,
      Thanks for the support.I did simple modify in coding.Now I got the output in the correct order.If i follow the step of it_tab-tdline = t_mara-matnr, it is storing in the column B as you mentioned.But it was displayed in the second line.So i did adjust your below coding.Finally got the solution.Thanks manish
    DATA wa_line LIKE LINE OF t_line.
    LOOP AT t_line INTO wa_line.
      it_tab-tdformat = wa_line-tdformat.
      it_tab-tdline = wa_line-tdline.
      it_tab-matnr = IT_TAB-matnr.
      APPEND it_tab.
    ENDLOOP.
    Regards,
    Kavi

  • To merge data in 1 internal table

    Hi Abap gurus,
    I have some probolem during merging data in internal table . I have four inernal tables and I want to merge data in one final internlal table. Is there any way of doing that without using nested loop ?
    It is urgent .

    Use the APPEND LINES statement.
    APPEND LINES OF: itab1 to final_itab,
                                   itab2 to final_itab,
                                   itab3 to final_itab. ...

  • Merge 2 internal tables into one and show first record from common fields

    Hello PPl,
              I have 3 tables kna1 knb1 and knvp i have to join kna1 and knb1 on kunnr and move the data into an internal table it_data then  on the basis of that data in it_data i have to retrieve records FOR ALL ENTRIES from KNVP and move it into it_knvp.
    Then both it_data and it_knvp should be merged in it_alv and from that internal table report has to be displayed.
    [NOTE: i had tried using loop twice but the report got messed up]
    Apart from that for these set of values
    0000000004
    0000000418
    0000000954
    0000001190
    0000001222
    0000001451
    0000001453
    0000001455
    0000001470
    0000001508
    finally knvp is showing records in such a way that for 2 records kunnr is same and so does all the other fields except PARZA and KUNN2 so the req. is to display only the first record among 2.
    Plz help me by providing code for that its urgent......
    Below i m providing my code so far, i hope it will be of some help.
    TREMENDOUS REWARD POINTS GURANTEED!!!!!
    REPORT  zfanz_alv_report_whv.
    TYPE-GROUPS                                                         *
    TYPE-POOLS: slis.
    TYPES                                                               *
    TYPES: BEGIN OF ty_data,
           kunnr TYPE kunnr,
           ort01 TYPE ort01,
           pstlz TYPE pstlz,
           regio TYPE regio,
           bukrs TYPE bukrs,
           zterm TYPE zterm,
           END OF ty_data,
           BEGIN OF ty_knvp,
           vkorg TYPE vkorg,
           vtweg TYPE vtweg,
           spart TYPE spart,
           parvw TYPE parvw,
           parza TYPE parza,
           kunn2 TYPE kunn2,
           lifnr TYPE lifnr,
           END OF ty_knvp,
           BEGIN OF ty_alv,
           kunnr TYPE kunnr,
           ort01 TYPE ort01,
           pstlz TYPE pstlz,
           regio TYPE regio,
           bukrs TYPE bukrs,
           zterm TYPE zterm,
           vkorg TYPE vkorg,
           vtweg TYPE vtweg,
           spart TYPE spart,
           parvw TYPE parvw,
           parza TYPE parza,
           kunn2 TYPE kunn2,
           lifnr TYPE lifnr,
           END OF ty_alv,
           BEGIN OF ty_kna1,
           kunnr TYPE kunnr,
           END OF ty_kna1,
           BEGIN OF ty_knb1,
           bukrs TYPE bukrs,
           END OF ty_knb1.
    *DATA: IT_KNVP TYPE KNVP,
    DATA: it_knvp TYPE STANDARD TABLE OF ty_knvp WITH HEADER LINE.
    DATA: it_data TYPE STANDARD TABLE OF ty_data WITH HEADER LINE.
    Report data to be shown.
    DATA: it_alv TYPE STANDARD TABLE OF ty_alv WITH HEADER LINE.
    Heading of the report.
    DATA: t_heading TYPE slis_t_listheader.
    *DATA: fieldcatalog type standard table of slis_fieldcat_alv with header
    *line.
    DATA: fieldcatalog TYPE  slis_t_fieldcat_alv WITH HEADER LINE.
    *TABLES
    tables:knvp,kna1,knb1.
                     CONSTANTS                                           *
    CONSTANTS: c_kunnr TYPE char5 VALUE 'KUNNR',
    c_ort01 TYPE char5 VALUE 'ORT01',
    c_pstlz TYPE char5 VALUE 'PSTLZ',
    c_regio TYPE char5 VALUE 'REGIO',
    c_bukrs TYPE char5 VALUE 'BUKRS',
    c_zterm TYPE char5 VALUE 'ZTERM',
    c_vkorg TYPE char5 VALUE 'VKORG',
    c_vtweg TYPE char5 VALUE 'VTWEG',
    c_spart TYPE char5 VALUE 'SPART',
    c_parvw TYPE char5 VALUE 'PARVW',
    c_parza TYPE char5 VALUE 'PARZA',
    c_kunn2 TYPE char5 VALUE 'KUNN2',
    c_lifnr TYPE char5 VALUE 'LIFNR'.
    WORKAREA                                                           *
    DATA: wa_data TYPE ty_data,
          wa_knvp TYPE ty_knvp,
          wa_alv TYPE ty_alv,
          wa_fcat  TYPE slis_fieldcat_alv,
          wa_layout TYPE slis_layout_alv.
    ======================= Selection Screen ==========================
    SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
    *DATA: wa_kunnr LIKE kna1-kunnr,
         wa_bukrs LIKE knb1-bukrs,
         wa_vkorg LIKE knvp-vkorg,
         wa_vtweg LIKE knvp-vtweg,
         wa_spart LIKE knvp-spart,
         wa_parvw LIKE knvp-parvw.
    SELECT-OPTIONS                                                      *
    SELECT-OPTIONS s_kunnr FOR kna1-kunnr NO INTERVALS OBLIGATORY
    SELECT-OPTIONS: s_bukrs FOR knb1-bukrs NO-EXTENSION NO INTERVALS,
    s_vkorg FOR knvp-vkorg  NO-EXTENSION NO INTERVALS,
    s_vtweg FOR knvp-vtweg NO-EXTENSION NO INTERVALS,
    s_spart FOR knvp-spart NO-EXTENSION NO INTERVALS,
    s_parvw FOR knvp-parvw NO-EXTENSION NO INTERVALS.
    SELECTION-SCREEN: END OF BLOCK b1.
    AT SELECTION-SCREEN                                            *
    AT SELECTION-SCREEN ON s_kunnr.
      PERFORM validate_data.
    START-OF-SELECTION                                                   *
    START-OF-SELECTION.
      PERFORM get_data.  "fetch data from table and perform join on them
      PERFORM final_table.
      PERFORM build_fieldcatalog.            "populate field catalog
      PERFORM build_layout.
      PERFORM grid_display.                  "display the result in ALV grid
    END-OF-SELECTION                                                     *
    END-OF-SELECTION.
    describe
    SUBROUTINES (FORMS)
    *&      Form  get_data
          Gets the information to be shown in the report.
          Join on tables KNA1, KNB1 and for all enteries in KNVP
    -->  p1        text
    <--  p2        text
    FORM get_data.
      SELECT kna1~kunnr
      kna1~ort01
      kna1~pstlz
      kna1~regio
      knb1~bukrs
      knb1~zterm
      INTO TABLE it_data
      FROM kna1 INNER JOIN knb1
      ON kna1kunnr = knb1kunnr
        WHERE kna1~kunnr IN s_kunnr
       AND knb1~bukrs IN s_bukrs.
      SELECT vkorg
             vtweg
             spart
             parvw
             parza
             kunn2
             lifnr
            INTO TABLE it_knvp FROM knvp
       FOR ALL ENTRIES IN it_data
       WHERE  knvp~kunnr = it_data-kunnr
         AND  vkorg IN s_vkorg
         AND  vtweg IN s_vtweg
         AND  spart IN s_spart
         AND  parvw IN s_parvw.
    ENDFORM. " get_data
    *ENDFORM. " get_data
    *&      Form  FINAL_TABLE
          text
    -->  p1        text
    <--  p2        text
    FORM final_table .
      LOOP AT it_data.
        it_alv-kunnr = it_data-kunnr.
        it_alv-ort01 = it_data-ort01.
        it_alv-pstlz = it_data-pstlz.
        it_alv-regio = it_data-regio.
        it_alv-bukrs = it_data-bukrs.
        it_alv-zterm = it_data-zterm.
        APPEND it_alv.
        CLEAR it_alv.
      ENDLOOP.
      LOOP AT it_knvp.
        it_alv-vkorg = it_knvp-vkorg.
        it_alv-vtweg = it_knvp-vtweg.
        it_alv-spart = it_knvp-spart.
        it_alv-parvw = it_knvp-parvw.
        it_alv-parza = it_knvp-parza.
        it_alv-kunn2 = it_knvp-kunn2.
        it_alv-lifnr = it_knvp-lifnr.
        APPEND it_alv.
        CLEAR it_alv.
      ENDLOOP.
    ENDFORM.                    " FINAL_TABLE
    *&      Form  BUILD_FIELDCATALOG
          Build Fieldcatalog for ALV Report
    FORM build_fieldcatalog.
      IF it_alv[] IS NOT INITIAL.
        wa_fcat-fieldname   = c_kunnr.
        wa_fcat-seltext_l   = 'Customer Master'(001).
        wa_fcat-col_pos     = 1.
        APPEND wa_fcat TO fieldcatalog.
        CLEAR  wa_fcat.
        wa_fcat-fieldname   = c_ort01.
        wa_fcat-seltext_l   = 'City'(002).
        wa_fcat-col_pos     = 2.
        APPEND wa_fcat TO fieldcatalog.
        CLEAR  wa_fcat.
        wa_fcat-fieldname   = c_pstlz.
        wa_fcat-seltext_l   = 'Postal Code'(003).
        wa_fcat-col_pos     = 3.
        APPEND wa_fcat TO fieldcatalog.
        CLEAR  wa_fcat.
        wa_fcat-fieldname   = c_regio.
        wa_fcat-seltext_l   = 'Region'(004).
        wa_fcat-col_pos     = 4.
        APPEND wa_fcat TO fieldcatalog.
        CLEAR  wa_fcat.
        wa_fcat-fieldname   = c_bukrs.
        wa_fcat-seltext_l   = 'Company Code'(005).
        wa_fcat-col_pos     = 5.
        APPEND wa_fcat TO fieldcatalog.
        CLEAR  wa_fcat.
        wa_fcat-fieldname   = c_zterm.
        wa_fcat-seltext_l   = 'Terms of payment'(006).
        wa_fcat-col_pos     = 6.
        APPEND wa_fcat TO fieldcatalog.
        CLEAR  wa_fcat.
        wa_fcat-fieldname   = c_vkorg.
        wa_fcat-seltext_l   = 'Sales Organization'(007).
        wa_fcat-col_pos     = 7.
        APPEND wa_fcat TO fieldcatalog.
        CLEAR  wa_fcat.
        wa_fcat-fieldname   = c_vtweg.
        wa_fcat-seltext_l   = 'Distribution Channel'(008).
        wa_fcat-col_pos     = 8.
        APPEND wa_fcat TO fieldcatalog.
        CLEAR  wa_fcat.
        wa_fcat-fieldname   = c_spart.
        wa_fcat-seltext_l   = 'Division'(009).
        wa_fcat-col_pos     = 9.
        APPEND wa_fcat TO fieldcatalog.
        CLEAR  wa_fcat.
        wa_fcat-fieldname   = c_parvw.
        wa_fcat-seltext_l   = 'Partner function'(010).
        wa_fcat-col_pos     = 10.
        APPEND wa_fcat TO fieldcatalog.
        CLEAR  wa_fcat.
        wa_fcat-fieldname   = c_kunn2.
        wa_fcat-seltext_l   = 'Customer number of partner'(011).
        wa_fcat-col_pos     = 11.
        APPEND wa_fcat TO fieldcatalog.
        CLEAR  wa_fcat.
        wa_fcat-fieldname   = c_lifnr.
        wa_fcat-seltext_l   = 'Account Number of Vendor'(012).
        wa_fcat-col_pos     = 12.
        APPEND wa_fcat TO fieldcatalog.
        CLEAR  wa_fcat.
       wa_fcat-fieldname   = c_parza.
       wa_fcat-seltext_l   = 'Partner counter'(013).
        wa_fcat-col_pos     = 13.
        APPEND wa_fcat TO fieldcatalog.
        CLEAR  wa_fcat.
    *fieldcatalog-fieldname   = c_kunnr.
       fieldcatalog-seltext_l   = 'Customer Master'(001).
       fieldcatalog-col_pos     = 1.
       APPEND fieldcatalog TO fieldcatalog.
       CLEAR  fieldcatalog.
       fieldcatalog-fieldname   = c_ort01.
       fieldcatalog-seltext_l   = 'City'(002).
       fieldcatalog-col_pos     = 2.
       APPEND fieldcatalog TO fieldcatalog.
       CLEAR  fieldcatalog.
       fieldcatalog-fieldname   = c_pstlz.
       fieldcatalog-seltext_l   = 'Postal Code'(003).
       fieldcatalog-col_pos     = 3.
       APPEND fieldcatalog TO fieldcatalog.
       CLEAR  fieldcatalog.
       fieldcatalog-fieldname   = c_regio.
       fieldcatalog-seltext_l   = 'Region'(004).
       fieldcatalog-col_pos     = 4.
       APPEND fieldcatalog TO fieldcatalog.
       CLEAR  fieldcatalog.
       fieldcatalog-fieldname   = c_bukrs.
       fieldcatalog-seltext_l   = 'Company Code'(005).
       fieldcatalog-col_pos     = 5.
       APPEND fieldcatalog TO fieldcatalog.
       CLEAR  fieldcatalog.
       fieldcatalog-fieldname   = c_zterm.
       fieldcatalog-seltext_l   = 'Terms of payment'(006).
       fieldcatalog-col_pos     = 6.
       APPEND fieldcatalog TO fieldcatalog.
       CLEAR  fieldcatalog.
       fieldcatalog-fieldname   = c_vkorg.
       fieldcatalog-seltext_l   = 'Sales Organization'(007).
       fieldcatalog-col_pos     = 7.
       APPEND fieldcatalog TO fieldcatalog.
       CLEAR  fieldcatalog.
       fieldcatalog-fieldname   = c_vtweg.
       fieldcatalog-seltext_l   = 'Distribution Channel'(008).
       fieldcatalog-col_pos     = 8.
       APPEND fieldcatalog TO fieldcatalog.
       CLEAR  fieldcatalog.
       fieldcatalog-fieldname   = c_spart.
       fieldcatalog-seltext_l   = 'Division'(009).
       fieldcatalog-col_pos     = 9.
       APPEND fieldcatalog TO fieldcatalog.
       CLEAR  fieldcatalog.
       fieldcatalog-fieldname   = c_parvw.
       fieldcatalog-seltext_l   = 'Partner function'(010).
       fieldcatalog-col_pos     = 10.
       APPEND fieldcatalog TO fieldcatalog.
       CLEAR  fieldcatalog.
       fieldcatalog-fieldname   = c_kunn2.
       fieldcatalog-seltext_l   = 'Customer number of partner'(011).
       fieldcatalog-col_pos     = 11.
       APPEND fieldcatalog TO fieldcatalog.
       CLEAR  fieldcatalog.
       fieldcatalog-fieldname   = c_lifnr.
       fieldcatalog-seltext_l   = 'Account Number of Vendor'(012).
       fieldcatalog-col_pos     = 12.
       APPEND fieldcatalog TO fieldcatalog.
       CLEAR  fieldcatalog.
       fieldcatalog-fieldname   = c_parza.
       fieldcatalog-seltext_l   = 'Partner counter'(013).
       fieldcatalog-col_pos     = 13.
       APPEND fieldcatalog TO fieldcatalog.
       CLEAR  fieldcatalog.
      ENDIF.
    ENDFORM.                    " BUILD_FIELDCATALOG
    *&      Form  build_layout
          text
    -->  p1        text
    <--  p2        text
    form build_layout .
    Set layout field for field attributes(i.e. input/output)
    wa_layout-stylefname = 'FIELD_STYLE'.
      wa_layout-zebra             = 'X'.
    endform.                    " build_layout
    *&      Form  GRID_DISPLAY
          text
    FORM grid_display. "using t_data type ty_tbl_data.
      IF it_alv[] IS NOT INITIAL.
        CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
         i_callback_program                = sy-repid
       IS_LAYOUT                         = wa_layout
         it_fieldcat                       = fieldcatalog[]
        TABLES
          t_outtab                          = it_alv[]
      EXCEPTIONS
            program_error            = 1
            OTHERS                   = 2.
        IF sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDIF.
      ENDIF.
    ENDIF.
    ENDFORM.                    "GRID_DISPLAY
    *&      Form  VALIDATE_DATA
          text
    -->  p1        text
    <--  p2        text
    FORM validate_data .
      DATA : li_kna1 TYPE STANDARD TABLE OF ty_kna1,
             li_knb1 TYPE STANDARD TABLE OF ty_knb1,
             li_knvp TYPE STANDARD TABLE OF ty_knvp.
      SELECT kunnr
      FROM kna1
      INTO TABLE li_kna1
      WHERE kunnr IN s_kunnr.
      IF sy-subrc <> 0.
        MESSAGE 'Invalid Customer Number'(013) TYPE 'E'.
      ENDIF.
      SELECT bukrs
      FROM t001
      INTO TABLE li_knb1
      WHERE bukrs IN s_bukrs.
        IF sy-subrc <> 0.
          MESSAGE 'Invalid Company Code'(014) TYPE 'E'.
        ENDIF.
        SELECT vkorg
        FROM tvko
        INTO TABLE li_knvp
        WHERE vkorg IN s_vkorg.
          IF sy-subrc <> 0.
            MESSAGE 'Invalid Sales Organization'(015) TYPE 'E'.
          ENDIF.
          SELECT vtweg
          FROM tvtw
          INTO TABLE li_knvp
          WHERE vtweg IN s_vtweg.
            IF sy-subrc <> 0.
              MESSAGE 'Invalid Distribution Channel'(016) TYPE 'E'.
            ENDIF.
            SELECT spart
            FROM tspa
            INTO TABLE li_knvp
            WHERE spart IN s_spart.
              IF sy-subrc <> 0.
                MESSAGE 'Invalid Division'(017) TYPE 'E'.
              ENDIF.
              SELECT parvw
              FROM tpar
              INTO TABLE li_knvp
              WHERE parvw IN s_parvw.
                IF sy-subrc <> 0.
                  MESSAGE 'Invalid Partner function'(018) TYPE 'E'.
                ENDIF.
            ENDFORM.                    " VALIDATE_DATA

    *1----
    FORM get_data.
      SELECT kna1~kunnr
      kna1~ort01
      kna1~pstlz
      kna1~regio
      knb1~bukrs
      knb1~zterm
      INTO TABLE it_data
      FROM kna1 INNER JOIN knb1
      ON kna1kunnr = knb1kunnr
        WHERE kna1~kunnr IN s_kunnr
       AND knb1~bukrs IN s_bukrs.
      CHECK it_data[] IS NOT INITIAL.
      SELECT kunnr
             vkorg
             vtweg
             spart
             parvw
             parza
             kunn2
             lifnr
            INTO TABLE it_knvp FROM knvp
       FOR ALL ENTRIES IN it_data
       WHERE  kunnr = it_data-kunnr
         AND  vkorg IN s_vkorg
         AND  vtweg IN s_vtweg
         AND  spart IN s_spart
         AND  parvw IN s_parvw.
      IF sy-subrc EQ 0.
        SORT it_knvp BY kunnr.
      ENDIF.
    ENDFORM. " get_data
    *2----
    FORM final_table .
      LOOP AT it_data INTO wa_data.
        READ TABLE it_knvp
        INTO wa_knvp
        WITH KEY kunnr = wa_data-kunnr
        BINARY SEARCH .
        IF sy-subrc = 0.
          MOVE-CORRESPONDING wa_data TO wa_alv.
          MOVE-CORRESPONDING wa_knvp TO wa_alv.
          APPEND wa_alv TO it_alv.
        ENDIF.
      ENDLOOP.
    ENDFORM.                    " FINAL_TABLE
    Edited by: Faisal Khan on Mar 27, 2008 1:59 PM

  • How to merge work areas of same internal table

    Hi Experts,
    I have a requirement to merge two work areas into 3rd work area where all 3 belonging to same internal table like example below.
            person | activity | location |
    wa1: 001     |    A       |              |
            person | activity | location |
    wa2: 001     |              | xyz       |
    after merging the value in wa3 should be as follows:
             person | activity | location |
    wa3: 001      |    A       |  xyz       |
    I am looking for a ABAP command or FM to perform this task.  Please help me on the same.
    Many Thanks,
    Vijay

    Hello,
    Try this:
    Field-symbols: <lfs_wa1> type line of lit1,
                     <lfs_wa2> type line of lit2.
      sort lit2 by field1 ascending.
      loop at lit1 assigning <lfs_wa1>.
        read table lit2 with key field1 = <lfs_wa1>-field1 assigning <lfs_wa2> binary search.
        clear wa3.
        wa3-field1 = <lfs_wa2>-field1.
        wa3-field2 = <lfs_wa2>-field2.
        wa3-field3 = <lfs_wa2>-field3.
        append wa3 to lit3.
      endloop.
    Use sorted internal tables, field symbols and binary search for better performance. In case when different fields in both work areas may be populated for each row, you need to implement some check and move logic inside loop instead of simple value assignment. I assume that the key value is always there for both tables you want to merge.
    best regards,
    Marcin
    Edited by: Marcin Makowski on Oct 20, 2010 7:16 PM
    Edited by: Marcin Makowski on Oct 20, 2010 7:17 PM

  • How to merge 4 internal tables

    Hi,
    I have to merge 4 internal tables
    Two loops have to create in main loop because getting more than one values from other table.
    Like
    LOOP AT it_itab1 INTO wa_itab1.
        MOVE-CORRESPONDING wa_itab1 TO wa_final.
        READ TABLE it_itab2 INTO wa_itab2 WITH KEY pspel = wa_itab1-pspnr.
        IF sy-subrc = 0.
          wa_final-aufnr = wa_itab2-aufnr.
        ENDIF.
        READ TABLE it_itab3 INTO wa_itab3 WITH KEY projn = wa_itab1-pspnr.
        IF sy-subrc = 0.
        wa_final-vornr = wa_itab3-vornr.
        ENDIF.
    Instead of this READ statement of internal table it_itab3, I need to put loop as follows. But how to merge with final table?
        loop at it_itab3 into wa_itab3 where projn = wa_itab1-pspnr.
         wa_final-vornr = wa_itab3-vornr.
        endloop.
        LOOP AT it_itab4 INTO wa_itab4 WHERE aufnr = wa_final-aufnr.
          wa_final-kzear  = wa_itab4-kzear.
          wa_final-matnr  = wa_itab4-matnr.
          wa_final-lgort  = wa_itab4-lgort.
          wa_final-sobkz  = wa_itab4-sobkz.
          wa_final-bdter  = wa_itab4-bdter.
          wa_final-bdmng  = wa_itab4-bdmng.
          wa_final-waers  = wa_itab4-waers.
          wa_final-aufnr  = wa_itab4-aufnr.
          wa_final-postp  = wa_itab4-postp.
          wa_final-posnr  = wa_itab4-posnr.
          wa_final-sanka  = wa_itab4-sanka.
          wa_final-gpreis = wa_itab4-gpreis.
          APPEND wa_final TO it_final.
          CLEAR:
          wa_itab4.
        ENDLOOP.
          CLEAR:wa_final,
          wa_itab1,
          wa_itab2,
          wa_itab3,
          wa_itab4.
      ENDLOOP.
    Pls help me to merge this table.
    Thanks in advance.
    Rajkumar Pandiaraja.

    Hi Raj,
    Do you have common key fields between final int table and other table?
    if yes then you can do this by,
    LOOP AT it_itab3 INTO wa_itab3 WHERE projn = wa_itab1-pspnr.
      wa_final-vornr = wa_itab3-vornr.
      MODIFY it_final FROM wa_final TRANSPORTING vornr
      WHERE key1 = wa_tab1-key1."Mention your key field here
    ENDLOOP.
    Regards,
    Manoj Kumar P
    Edited by: Manoj Kumar on Jan 23, 2009 12:20 PM
    Edited by: Manoj Kumar on Jan 23, 2009 12:21 PM

  • How to merge 3 or more internal tables?

    Hi SDN,
    I am having 3 internal tables with some comman fields.
    I want to merge them based on the comman fields having the same values.
    Can any tell me is there any way to do this?
    Or any FM for this?
    Regards,
    Rahul

    Syntax for TWO TABLES JOIN:
    select vbeln "sales order no
    erdat "date
    posnr "sales order item
    netwt "net value
    from vbak as a
    inner join vbap as b on avbeln = bvbeln
    into table itab
    where vbeln in s_vbeln.
    Conditions:
    1.There must be one field common in both table(JUST LIKE VBELN in the above example)
    2.If u using select-options u use IN operator in WHERE clause
    Here itab means internal table.
    syntax for Joining 3 tables
    select vbeln
    erdat
    posnr
    rfsta
    from vbak as a
    inner join vbap as b on avbeln = bvbeln
    inner join vbup as c on avbeln = cvbeln
    where vbeln in s_vbeln.
    U BETTER TO USE JOIN UPTO 4 TABLES.IF U GO BEYOND THAT UR PERFORMANCE OF THE PROGRAM IS DEGRATED.
    AT THAT TIME U BETTER TO USE "FOR ALL ENTRIES"..

  • Merging two internal tables

    Hi,
    I have two internal tables it_tab1 and it_tab2. The fields are,
    it_tab1                        it_tab2
    F1                    F1
    F2                    F2
    F3                    F4
    F6                    F5
    I want to <b>merge</b>(coloumn wise) these two internal tables into a new internal table it_tab3 where it_tab3 has fields,
    F1, F2, F3, F4, F5, F6.(All the fields)
    Here, in it_tab1 and in it_tab2 the fields <b>F1 and F2 are the key fields</b>.The number of records in the two internal tables are different.
    Can anybody help me. thanx for spending ur time.

    hi,
    try this
    hi,
    itab1 - first
    itab2 - second
    itab3 - both
    data l_count type i.
    l_count = 1.
    loop at itab1.
    read table itab2 with key f1 = itab1-f1 f2 = itab1-f2.
    itab3 = itab1
    if sy-subrc is initial
       itab3-field6 = itab2-field3.
       itab3-field7 = itab2-field4.
       append itab3.
    endif.
    endloop.
    loop at itab2.
    itab3 = itab2
    read table itab1 with key f1 = itab2-f1 f2 = itab2-f2.
    if sy-subrc is initial
       itab3-field6 = itab1-field3.
       itab3-field7 = itab1-field4.
       append itab3.
    endif.
    endloop.
    sort itab3 by f1 f2.
    delete adjacent duplicates by comparing f1 f2.
    hope this will solve your problem
    cheers,
    sasi
    Cheers,
    Sasi

  • Merge an internal table into a string stream

    Hello,
    i need to merge an internal table (2 column) layout:
    ELEMENT
    VALUE
    into one string stream.
    E.g.:
    ELEMENT | VALUE
    test1   | 1111111111111111111
    test1   | 2222222222222222222
    result should be:
    test1   | 11111111111111111112222222222222222222 (= type string!)
    too bad you cant use offset while working with a field of type string and im sure there is a ABAP class which does do this.
    regards,
    Markus

    Try this Markus:
    REPORT ztest NO STANDARD PAGE HEADING LINE-SIZE 255.
    DATA: BEGIN OF itab OCCURS 0,
            element TYPE string,
            value   TYPE string,
          END   OF itab.
    DATA: BEGIN OF itab2 OCCURS 0,
            element TYPE string,
            value   TYPE string,
          END   OF itab2.
    DATA: next LIKE sy-tabix VALUE 1,
          old_element LIKE itab-element.
    PERFORM load_itab.
    sy-subrc = 0.
    DO.
      READ TABLE itab INDEX next.
      IF sy-subrc <> 0.
        EXIT.
      ELSE.
        IF itab-element <> old_element.
          IF next <> 1.
            APPEND itab2.
            CLEAR itab2.
          ENDIF.
          itab2-element = itab-element.
          old_element = itab-element.
        ENDIF.
        CONCATENATE itab2-value itab-value INTO itab2-value.
        next = next + 1.
      ENDIF.
    ENDDO.
    IF itab2-element <> space.
      APPEND itab2.
    ENDIF.
    break rburbank.
    *&      Form  load_itab
    *       text
    FORM load_itab.
      REFRESH: itab,
               itab2.
      CLEAR  : itab,
               itab2.
      itab-element = 'test1'.
      itab-value   = '1111111111111111111'.
      APPEND itab.
      itab-element = 'test1'.
      itab-value   = '2222222222222222222'.
      APPEND itab.
      itab-element = 'test2'.
      itab-value   = '3333333333333333333'.
      APPEND itab.
      itab-element = 'test2'.
      itab-value   = '4444444444444444444'.
      APPEND itab.
    ENDFORM.                    " load_itab
    Rob

  • How to merge All text fiels into 1 text file to read into internal table

    Hi dudes,
      I have 3 text files in workstation. I need to everytime download these files in my internal table .
      But it takes long processing time .ie everytime it opens file read and close.
      Do u suggest for better performance for this? Like how i can meage all txt files in 1 txt file and then read once ito internal table.
      Hope i m clear to explain u my requirement.
      Gain Points

    It actually depends on your requirement(a standard answer from any SAP guy).
    Coming back to the question at hand:
    a) Can we merge these files ? My question to you :
    i) Are you downloading these to your presentation server from application server using WS_DOWNLOAD(I am using 4.5B) or CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD ?
    ii) What holds you back ?
    b) How do we parse multiple files contained in a single file ?
    Keep a delimiter which is unique only for file endings. That should do the trick.
    Regards,
    Subramanian V.

Maybe you are looking for

  • How to find out who is using the shared library?

    Is there a way to find out who is listening to my music on my shared library and what they are listening to?

  • Still no Broadband!

    I've been waiting for my Broadband to be set up for just over a week now. First I was told it would be done on 25th March, but then it was discovered that there was a fault on the exchange that moved it to at least Monday 30th March. On Monday I was

  • Import-Module ActiveDirectory - Error - after upgrading DC's to 2012 R2

    Hi. We done upgrading our Domain Controllers to 2012 R2 Version, and after upgrade i can't use ActiveDirectory  module outside my DC When i\m trying to run  Import-Module ActiveDirectory on my Windows 7 desktop i get error: WARNING: Error initializin

  • The data that is in the table is from excel, so the data to be read can changed?

    for example the data before is EXEC 1,how if i'll changed the value to 1 how can i read those data if he changed the EXEC 1 to 1. that's why i said the data is changeable. can you give me a simple example about this? Thank You

  • Need new Connect development info

    For Connect/Breeze 5 and 6, our company had been granted access to the "Breeze Telephony Adapter Reference" and the "Telephony Adapter API". We used this to integrate our own teleconferencing product into a Connect licensed server. When I try calling