Register Login

Insert Internal Table fields to Corresponding final Internal Table

Updated May 18, 2018

I have some 100 records in one internal table and another 100 records in another internal table.finally i have one final internal table with all the fields of the above two itabs.what i want is i have to insert the internal table fields into corresponding final internal table.

What I have done is looping these internal tables into work and append it into final itab. But I couldn't get the exact answer because the second set of records appended after the first set of records.can any one help me.


Comments

  • 17 May 2012 7:16 am vishal singh Helpful Answer
    *&---------------------------------------------------------------------*
    *& Report ZVIS_RDD002_DELIVERY_REPORT2
    *& AUTHOR : VISHAL SINGH
    *& TITLE : DELIVERY REPORT
    *& DESCRIPTION : THIS REPORT IS USED TO DISPLAY ALL THE DELIVERY HEADER
    *& ITEM AND CORRESPONDING SHIP TO PARTY DETAILS WITH CONTROL
    *& BREAK EVENTS (AT FIRST AT LAST AT NEW END AT).
    *& VCEK901019
    *& VERSION : V1
    *&---------------------------------------------------------------------*
    *&
    *&
    *&---------------------------------------------------------------------*

    REPORT ZVIS_RDD005_DEL_REP1
    NO STANDARD PAGE HEADING
    LINE-SIZE 145
    LINE-COUNT 35(4).


    *&---------------------------------------------------------------------*
    *& STRUCTURE DECLARATIONS .
    *&---------------------------------------------------------------------*

    * STRUCTURE DECLARATION FOR DELIVERY HEADER .

    TYPES : BEGIN OF TY_LIKP,
    VBELN TYPE VBELN_VL , "DELIVERY NO
    VKORG TYPE VKORG , "SALES ORGANIZATION
    LFART TYPE LFART , "DELIVERY TYPE
    LDDAT TYPE LDDAT , "LOADING DATE
    KUNNR TYPE KUNNR , "SHIP TO PARTY
    END OF TY_LIKP ,


    * STRUCTURE DECLARATION FOR DELIVERY ITEM .

    BEGIN OF TY_LIPS ,
    VBELN TYPE VBELN_VA , "DELIVERY NO
    POSNR TYPE POSNR_VL , "DELIVERY ITEM
    MATNR TYPE MATNR , "MATERIAL NO
    MATKL TYPE MATKL , "MATERIAL GROUP
    WERKS TYPE WERKS_D , "PLANT
    LGORT TYPE LGORT_D , "STORAGE LOCATION
    NTGEW TYPE NTGEW_15 , "NET WEIGHT
    END OF TY_LIPS ,

    * STRUCTURE DECLARATION FOR SHIP TO PARTY.

    BEGIN OF TY_KNA1 ,
    KUNNR TYPE KUNNR , "SHIP TO PARTY
    NAME1 TYPE NAME1 , "CUSTOME NAME
    ORT01 TYPE ORT01 , "CITY
    PSTLZ TYPE PSTLZ , "POSTAL CODE
    REGIO TYPE REGIO , "REGION
    END OF TY_KNA1 ,

    * STRUCTURE DECLARATION FOR FINAL OUTPUT .

    BEGIN OF TY_OUTPUT,
    VBELN TYPE VBELN_VL , "DELIVERY NO
    VKORG TYPE VKORG , "SALES ORGANIZATION
    LFART TYPE LFART , "DELIVERY TYPE
    LDDAT TYPE LDDAT , "LOADING DATE
    KUNNR TYPE KUNNR , "SHIP TO PARTY

    POSNR TYPE POSNR_VL , "DELIVERY ITEM
    MATNR TYPE MATNR , "MATERIAL NO
    MATKL TYPE MATKL , "MATERIAL GROUP
    WERKS TYPE WERKS_D , "PLANT
    LGORT TYPE LGORT_D , "STORAGE LOCATION
    NTGEW TYPE NTGEW_15 , "NET WEIGHT

    NAME1 TYPE NAME1 , "CUSTOME NAME
    ORT01 TYPE ORT01 , "CITY
    PSTLZ TYPE PSTLZ , "POSTAL CODE
    REGIO TYPE REGIO , "REGION
    END OF TY_OUTPUT .

    *&---------------------------------------------------------------------*
    *& INTERNAL TABLE DECLARATION
    *&---------------------------------------------------------------------*

    * INTERNAL TABLE DECLARATION FOR DELIVERY HEADER.

    DATA : T_LIKP TYPE STANDARD TABLE OF TY_LIKP INITIAL SIZE 0,

    * INTERNAL TABLE DECLARATION FOR DELIVERY ITEM.

    T_LIPS TYPE STANDARD TABLE OF TY_LIPS INITIAL SIZE 0,

    * INTERNAL TABLE DECLARATION FOR SHIP TO PARTY .

    T_KNA1 TYPE STANDARD TABLE OF TY_KNA1 INITIAL SIZE 0 ,

    * INTERNAL TABLE DECLARATION FOR FINAL OUTPUT.

    T_OUTPUT TYPE STANDARD TABLE OF TY_OUTPUT INITIAL SIZE 0 .

    *&---------------------------------------------------------------------*
    *& WORK AREA DECLARATION
    *&---------------------------------------------------------------------*

    * WORK AREA DECLARATION FOR DELIVERY HEADER .
    DATA : W_LIKP TYPE TY_LIKP,

    * WORK AREA DECLARATION FOR DELIVERY ITEM.
    W_LIPS TYPE TY_LIPS,

    * WORK AREA DECLARATION FOR SHIP TO PARTY.
    W_KNA1 TYPE TY_KNA1,

    * WORK AREA DECLARATION FOR FINAL OUTPUT.
    W_OUTPUT TYPE TY_OUTPUT,
    W_OUTPUT1 TYPE TY_OUTPUT.

    *&---------------------------------------------------------------------*
    *& GLOBAL VARIABLE DECLARATION
    *&---------------------------------------------------------------------*
    DATA : G_VBELN TYPE LIKP-VBELN.

    *&---------------------------------------------------------------------*
    *& SELECTION SCREEN DECLARATION
    *&---------------------------------------------------------------------*
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
    SELECT-OPTIONS : S_VBELN FOR G_VBELN.
    SELECTION-SCREEN END OF BLOCK B1.

    *&---------------------------------------------------------------------*
    *& INITIALIZATION EVENT
    *&---------------------------------------------------------------------*
    INITIALIZATION.

    * CLEAR WORK AREAS .
    CLEAR : W_LIKP,
    W_LIPS,
    W_KNA1,
    W_OUTPUT.

    * REFRESH THE INTERNAL TABLES .
    REFRESH : T_LIKP,
    T_LIPS,
    T_KNA1,
    T_OUTPUT.

    *&---------------------------------------------------------------------*
    *& AT SELECTION-SCREEN EVENT DECLARATION
    *&---------------------------------------------------------------------*
    AT SELECTION-SCREEN.
    *
    * VALIDATE DELIVERY NUMBER.
    PERFORM SUB_VALIDATE_VBELN.

    *&---------------------------------------------------------------------*
    *& START OF SELECTION EVENT
    *&---------------------------------------------------------------------*
    START-OF-SELECTION.

    * GET LIKP DATA .
    PERFORM SUB_GET_LIKP.

    * GET LIPS DATA.
    PERFORM SUB_GET_LIPS.

    * GET KNA1 DATA.
    PERFORM SUB_GET_KNA1.

    * GET FINAL OUTPUT DATA .
    PERFORM SUB_DISP_OUTPUT.

    *************************************************
    ** TOP-OF-PAGE
    *************************************************
    TOP-OF-PAGE.
    WRITE : /35 'DELIVERY REPORT '.
    ULINE.
    WRITE : /02 'DELIVERY NUM',
    20 'SALES ORG',
    35 'LOAD DATE',
    50 'SHIP TO PARTY',
    80 'CUST NAME',
    95 'CITY',
    110 'POSTAL CODE'.

    WRITE : /02 'DEL ITEM',
    20 'MATERIAL',
    36 'MAT GRP',
    50 'NET VALUE'.

    ULINE.

    *&---------------------------------------------------------------------*
    *& Form SUB_VALIDATE_VBELN
    *&---------------------------------------------------------------------*
    * THIS ROUTINE IS USED TO VALIDATE THE DELIVERY NO.
    *----------------------------------------------------------------------*
    FORM SUB_VALIDATE_VBELN .
    DATA : L_VBELN TYPE VBELN_VL.

    SELECT SINGLE VBELN
    FROM VBUK
    INTO L_VBELN
    WHERE VBELN IN S_VBELN.

    IF SY-SUBRC <> 0.
    MESSAGE E003(ZBATCH35) WITH 'DATA NOT FOUND FOR GIVEN RANGE'.

    ENDIF.

    ENDFORM. " SUB_VALIDATE_VBELN
    *&---------------------------------------------------------------------*
    *& Form SUB_GET_LIKP
    *&---------------------------------------------------------------------*
    * THIS ROUTINE IS USED TO GET DELIVERY HEADER
    *----------------------------------------------------------------------*
    FORM SUB_GET_LIKP .
    SELECT VBELN
    VKORG
    LFART
    LDDAT
    KUNNR
    FROM LIKP
    INTO TABLE T_LIKP
    WHERE VBELN IN S_VBELN.

    IF SY-SUBRC <> 0.
    MESSAGE I002(ZBATCH35) WITH 'WRONG DATA ENTERED'.
    LEAVE LIST-PROCESSING.
    ENDIF.

    ENDFORM. " SUB_GET_LIKP
    *&---------------------------------------------------------------------*
    *& Form SUB_GET_LIPS
    *&---------------------------------------------------------------------*
    * THIS ROUTINE IS USED TO DISPLAY LIPS DATA
    *----------------------------------------------------------------------*
    FORM SUB_GET_LIPS .

    SELECT VBELN
    POSNR
    MATNR
    MATKL
    WERKS
    LGORT
    NTGEW
    FROM LIPS
    INTO TABLE T_LIPS
    FOR ALL ENTRIES IN T_LIKP
    WHERE VBELN = T_LIKP-VBELN.


    ENDFORM. " SUB_GET_LIPS
    *&---------------------------------------------------------------------*
    *& Form SUB_GET_KNA1
    *&---------------------------------------------------------------------*
    * THIS ROUTINE IS USED TO DISPLAY SHIP TO PARTY DATA
    *----------------------------------------------------------------------*
    FORM SUB_GET_KNA1 .
    SELECT KUNNR
    NAME1
    ORT01
    PSTLZ
    REGIO
    FROM KNA1
    INTO TABLE T_KNA1
    FOR ALL ENTRIES IN T_LIKP
    WHERE KUNNR = T_LIKP-KUNNR.

    ENDFORM. " SUB_GET_KNA1
    *&---------------------------------------------------------------------*
    *& Form SUB_DISP_OUTPUT
    *&---------------------------------------------------------------------*
    * THIS ROUTINE IS USED TO DISPLAY THE FINAL OUTPUT
    *----------------------------------------------------------------------*
    FORM SUB_DISP_OUTPUT .

    LOOP AT T_LIPS INTO W_LIPS.
    * MOVING DELIVERY ITEM DATA TO THE FINAL OUTPUT.

    W_OUTPUT-VBELN = W_LIPS-VBELN.
    W_OUTPUT-POSNR = W_LIPS-POSNR.
    W_OUTPUT-MATNR = W_LIPS-MATNR.
    W_OUTPUT-MATKL = W_LIPS-MATKL.
    W_OUTPUT-WERKS = W_LIPS-WERKS.
    W_OUTPUT-LGORT = W_LIPS-LGORT.
    W_OUTPUT-NTGEW = W_LIPS-NTGEW.

    * MOVING DELIVERY HEADER DATA TO FINAL OUTPUT.

    CLEAR W_LIKP.
    READ TABLE T_LIKP INTO W_LIKP WITH KEY VBELN = W_LIPS-VBELN.
    IF SY-SUBRC = 0.
    W_OUTPUT-VKORG = W_LIKP-VKORG.
    W_OUTPUT-LFART = W_LIKP-LFART.
    W_OUTPUT-LDDAT = W_LIKP-LDDAT.
    W_OUTPUT-KUNNR = W_LIKP-KUNNR.
    ENDIF.

    * MOVING SHIP TO PARTY DATA TO FINAL OUTPUT.

    CLEAR W_KNA1.
    READ TABLE T_KNA1 INTO W_KNA1 WITH KEY KUNNR = W_LIKP-KUNNR.
    IF SY-SUBRC = 0.
    W_OUTPUT-NAME1 = W_KNA1-NAME1.
    W_OUTPUT-ORT01 = W_KNA1-ORT01.
    W_OUTPUT-PSTLZ = W_KNA1-PSTLZ.
    W_OUTPUT-REGIO = W_KNA1-REGIO.
    ENDIF.

    APPEND W_OUTPUT TO T_OUTPUT.
    CLEAR W_OUTPUT.
    ENDLOOP.


    *&---------------------------------------------------------------------*
    *& DISPLAYING THE FINAL OUTPUT.
    *&---------------------------------------------------------------------*


    LOOP AT T_OUTPUT INTO W_OUTPUT1.
    W_OUTPUT = W_OUTPUT1.

    AT NEW VBELN.
    * ULINE.
    WRITE : /02 W_OUTPUT-VBELN,
    20 W_OUTPUT-VKORG,
    35 W_OUTPUT-LDDAT,
    55 W_OUTPUT-KUNNR,
    80 W_OUTPUT-NAME1,
    95 W_OUTPUT-ORT01,
    110 W_OUTPUT-PSTLZ.
    ULINE.
    ENDAT.
    * ULINE.
    WRITE : /02 W_OUTPUT-POSNR,
    20 W_OUTPUT-MATNR,
    36 W_OUTPUT-MATKL,
    45 W_OUTPUT-NTGEW.


    * SUBTOTALS
    ************************************************
    AT END OF VBELN.
    ULINE.
    SUM.
    WRITE : /30 'SUBTOTAL : ' ,45 W_OUTPUT1-NTGEW.
    ULINE.
    ENDAT.
    * ULINE.

    * GRANDTOTALS
    ************************************************
    AT LAST.
    SUM.
    WRITE : /35 'GRANDTOTALS :', 50 W_OUTPUT1-NTGEW.
    ENDAT.
    ENDLOOP.

    ENDFORM. " SUB_DISP_OUTPUT


    **
    ************************************************
    * END-OF-PAGE
    ************************************************
    END-OF-PAGE.
    ULINE.
    WRITE : /35 'END OF PAGE :' ,SY-PAGNO.
  • 09 Jul 2014 11:14 pm Saurabh Nayyar

    Hi,

     

    Just want to add one more thing. If there can be multiple entries in second table for the values in the work area of table1 then use can use the paralled cursor technique and add a mutiple reocrds to the final internal table.

    If you have any doubts mail me snayyar24@gmail.com

     


×