6 Replies Latest reply: Jan 12, 2009 1:22 PM by Murugesh P RSS

Material master uploading using BAPI's

Murugesh P
Currently Being Moderated

hi abapers,

                 how to upload data from xl sheet to sap using BAPI's.

 

Regards

Murugesh

  • Re: Material master uploading using BAPI's
    Vishwa Srihari
    Currently Being Moderated

    Hi

     

    Use ALSM_EXCEL_TO_INTERNAL_TABLE to upload the excel file into an internal table. Then pass on the data to the BAP parameters.

     

    P.S: If you search in SCN with the search term BAPI sample code, you wil get many results. You can get sample code for the excel FM mentioned above.

     

    VIshwa.

  • Re: Material master uploading using BAPI's
    Asit Purbey
    Currently Being Moderated

    Hi,

        After uploading your data in internal table, make use of Bapi "BAPI_MATERIAL_SAVEREPLICA".

  • Re: Material master uploading using BAPI's
    Raju Chitale
    Currently Being Moderated

    Hi,

     

    Have a look @this:

     

     TABLES bapi_MVKEx.
    *----------------------------------------------------------------------*
    *----------------------------------------------------------------------*
    * FLAGS
    *----------------------------------------------------------------------*
    DATA: F_STOP. " Flag used to stop processing
    
    *----------------------------------------------------------------------*
    * DATA DECLARATIONS
    *----------------------------------------------------------------------*
    DATA : V_EMPTY TYPE I, " No. of empty records
           V_TOTAL TYPE I. " Total no. of records.
    
    *----------------------------------------------------------------------*
    * STRUCTURES & INTERNAL TABLES
    *----------------------------------------------------------------------*
    *--- BAPI structures
    DATA: BAPI_HEAD LIKE BAPIMATHEAD, " Header Segment with Control
                                      "Information
    BAPI_MAKT LIKE BAPI_MAKT, " Material Description
    BAPI_MARA1 LIKE BAPI_MARA, " Client Data
    BAPI_MARAX LIKE BAPI_MARAX, " Checkbox Structure for BAPI_MARA
    BAPI_MARC1 LIKE BAPI_MARC, " Plant View
    BAPI_MARCX LIKE BAPI_MARCX, " Checkbox Structure for BAPI_MARC
    BAPI_MBEW1 LIKE BAPI_MBEW, " Accounting View
    BAPI_MBEWX LIKE BAPI_MBEWX, " Checkbox Structure for BAPI_MBEW
    BAPI_MVKE1 LIKE BAPI_MVKE, "Sales Data
    BAPI_RETURN LIKE BAPIRET2. " Return Parameter
    DATA: return     LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
    
    *--- Internal table to hold excel file data
    DATA: IT_INTERN TYPE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
    
    *--- Internal table to hold Matetrial descriptions
    DATA: BEGIN OF IT_MAKT OCCURS 100.
    INCLUDE STRUCTURE BAPI_MAKT.
    DATA: END OF IT_MAKT.
    
    *--- Internal to hold the records in the text file
    DATA : BEGIN OF IT_DATA OCCURS 100,
    WERKS(4), " Plant
    MTART(4), " Material type
    MATNR(18), " Material number
    MATKL(9) , " Material group
    MBRSH(1), " Industry sector
    MEINS(3), " Base unit of measure
    GEWEI(3), " Weight Unit
    SPART(2), " Division
    EKGRP(3), " Purchasing group
    VPRSV(1), " Price control indicator
    STPRS(12), " Standard price
    PEINH(3), " Price unit
    SPRAS(2), " Language key
    MAKTX(40), " Material description
    MTPOS_MARA(4), "Item Category Group
    vkorg(4), "Sales Org
    vtweg(2), "Dist channel
    Prdha(18), "Prod Hierarchy
    ladgr(4), " Loading Group
    prctr(10), "Profit Centr
    xchpf(1), "Batch Mgmt
    kondm(2), "Material Pricing Grp
    ktgrm(2), "Account Assignment Grp
    mvgr1(4),
    mvgr2(4),
    mvgr3(4),
    versg(1), "Material Statistics Grp
    * Added fields not part of the layout
    sapmatnr(18),
    END OF IT_DATA.
    
    *----------------------------------------------------------------------*
    * SELECTION SCREEN. *
    *----------------------------------------------------------------------*
    SELECTION-SCREEN BEGIN OF BLOCK SCR1 WITH FRAME TITLE TEXT-111.
    PARAMETER : P_FILE TYPE RLGRAP-FILENAME OBLIGATORY DEFAULT " Input File
    'H:\DATA\Nova\rbc\zrbc129.xls'.
    PARAMETER : P_MAX(4) OBLIGATORY DEFAULT '100'. " no.of recs in a session
    PARAMETERS: P_HEADER TYPE I DEFAULT 0. " Header Lines
    PARAMETERS: P_BEGCOL TYPE I DEFAULT 1 NO-DISPLAY,
    P_BEGROW TYPE I DEFAULT 1 NO-DISPLAY,
    P_ENDCOL TYPE I DEFAULT 100 NO-DISPLAY,
    P_ENDROW TYPE I DEFAULT 32000 NO-DISPLAY.
    SELECTION-SCREEN END OF BLOCK SCR1.
    
    *---------------------------------------------------------------------*
    * AT SELECTION-SCREEN
    *---------------------------------------------------------------------*
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
    *--- Validating file
    PERFORM VALIDATE_FILE USING P_FILE.
    
    *----------------------------------------------------------------------*
    * START-OF-SELECTION
    *----------------------------------------------------------------------*
    START-OF-SELECTION.
    *--- Perform to convert the Excel data into an internal table
    PERFORM CONVERT_XLS_ITAB.
    IF NOT IT_DATA[] IS INITIAL.
    *--- Perform to delete Header lines
    PERFORM DELETE_HEADER_EMPTY_RECS.
    ENDIF.
    *----------------------------------------------------------------------*
    * END OF SELECTION.
    *----------------------------------------------------------------------*
    END-OF-SELECTION.
    *--- Perform to upload Material Master data
    PERFORM UPLOAD_MATMAS.
    
    *----------------------------------------------------------------------*
    * Form : validate_input_file
    *----------------------------------------------------------------------*
    * Description : To provide F4 help for file if read from PC
    *----------------------------------------------------------------------*
    FORM VALIDATE_FILE USING F_FILE TYPE RLGRAP-FILENAME.
    CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    exporting
    STATIC = 'X'
    CHANGING
    FILE_NAME = F_FILE
    EXCEPTIONS
    MASK_TOO_LONG = 1
    OTHERS = 2.
    IF SY-SUBRC <> 0.
    *MESSAGE S010" 'Error in getting filename'.
    ENDIF.
    ENDFORM. " validate_input_file
    
    *&---------------------------------------------------------------------*
    *& Form CONVER_XLS_ITAB
    *&---------------------------------------------------------------------*
    * To convert XLS to internal table
    *----------------------------------------------------------------------*
    FORM CONVERT_XLS_ITAB.
    CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
    FILENAME = P_FILE
    I_BEGIN_COL = P_BEGCOL
    I_BEGIN_ROW = P_BEGROW
    I_END_COL = P_ENDCOL
    I_END_ROW = P_ENDROW
    TABLES
    INTERN = IT_INTERN.
    IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    *--- Perform to move the data into an internal data
    PERFORM MOVE_DATA.
    ENDFORM. " CONVERT_XLS_ITAB
    *&---------------------------------------------------------------------*
    *& Form MOVE_DATA
    *&---------------------------------------------------------------------*
    * text
    *----------------------------------------------------------------------*
    FORM MOVE_DATA.
    DATA : LV_INDEX TYPE I.
    FIELD-SYMBOLS: <fs> type any.
    *--- Sorting the internal table
    SORT IT_INTERN BY ROW COL.
    CLEAR IT_INTERN.
    LOOP AT IT_INTERN.
    MOVE IT_INTERN-COL TO LV_INDEX.
    *--- Assigning the each record to an internal table row
    ASSIGN COMPONENT LV_INDEX OF STRUCTURE IT_DATA TO <fs>.
    *--- Asigning the field value to a field symbol
    <fs> = it_intern-value.
    *MOVE IT_INTERN-VALUE TO <fs>.
    AT END OF ROW.
    APPEND IT_DATA.
    CLEAR IT_DATA.
    ENDAT.
    ENDLOOP.
    ENDFORM. " MOVE_DATA
    *&---------------------------------------------------------------------*
    *& Form DELETE_HEADER_EMPTY_RECS
    *&---------------------------------------------------------------------*
    * To delete the Header and empty records
    *----------------------------------------------------------------------*
    FORM DELETE_HEADER_EMPTY_RECS.
    DATA: LV_TABIX LIKE SY-TABIX.
    IF NOT P_HEADER IS INITIAL.
    LOOP AT IT_DATA.
    IF P_HEADER > 0 AND NOT IT_DATA IS INITIAL.
    DELETE IT_DATA FROM 1 TO P_HEADER.
    * P_HEADER = 0.
    EXIT.
    ENDIF.
    ENDLOOP.
    ENDIF.
    CLEAR IT_DATA.
    *--- To delete the empty lines from internal table
    LOOP AT IT_DATA.
    LV_TABIX = SY-TABIX.
    IF IT_DATA IS INITIAL.
    V_EMPTY = V_EMPTY + 1.
    DELETE IT_DATA INDEX LV_TABIX..
    ENDIF.
    ENDLOOP.
    CLEAR IT_DATA.
    *--- Total no of recs in file
    DESCRIBE TABLE IT_DATA LINES V_TOTAL.
    IF V_TOTAL = 0.
    *MESSAGE I013" No records in the file
    F_STOP = 'X'.
    STOP.
    ENDIF.
    ENDFORM. " DELETE_HEADER_EMPTY_RECS
    *&---------------------------------------------------------------------*
    *& Form UPLOAD_MATMAS
    *&---------------------------------------------------------------------*
    * to upload Material Master data
    *----------------------------------------------------------------------*
    FORM UPLOAD_MATMAS .
    LOOP AT IT_DATA.
    * Header
    CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
      EXPORTING
        input              = it_data-matnr
     IMPORTING
       OUTPUT             =  it_data-sapmatnr
     EXCEPTIONS
       LENGTH_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.
    
    BAPI_HEAD-MATERIAL = IT_DATA-sapMATNR.
    BAPI_HEAD-IND_SECTOR = IT_DATA-MBRSH.
    BAPI_HEAD-MATL_TYPE = IT_DATA-MTART.
    BAPI_HEAD-BASIC_VIEW = 'X'.
    BAPI_HEAD-PURCHASE_VIEW = 'X'.
    BAPI_HEAD-ACCOUNT_VIEW = 'X'.
    BAPI_HEAD-SALES_VIEW = 'X'.
    BAPI_HEAD-QUALITY_VIEW = 'X'.
    * Material Description
    REFRESH IT_MAKT.
    IT_MAKT-LANGU = IT_DATA-SPRAS.
    IT_MAKT-MATL_DESC = IT_DATA-MAKTX.
    APPEND IT_MAKT.
    * Client Data - Basic
    BAPI_MARA1-MATL_GROUP = IT_DATA-MATKL.
    BAPI_MARA1-BASE_UOM = IT_DATA-MEINS.
    BAPI_MARA1-UNIT_OF_WT = IT_DATA-GEWEI.
    BAPI_MARA1-DIVISION = IT_DATA-SPART.
    BAPI_MARA1-item_cat = it_data-mtpos_mara.
    BAPI_MARA1-PROD_HIER = it_data-prdha.
    bapi_marax-item_cat = 'X'.
    bapi_marax-prod_hier = 'X'.
    BAPI_MARAX-MATL_GROUP = 'X'.
    BAPI_MARAX-BASE_UOM = 'X'.
    BAPI_MARAX-UNIT_OF_WT = 'X'.
    BAPI_MARAX-DIVISION = 'X'.
    * Plant - Purchasing
    BAPI_MARC1-PLANT = IT_DATA-WERKS.
    BAPI_MARC1-PUR_GROUP = IT_DATA-EKGRP.
    BAPI_MARC1-LOADINGGRP = IT_DATA-LADGR.
    BAPI_MARC1-PROFIT_CTR = IT_DATA-prctr.
    BAPI_MARC1-BATCH_MGMT = IT_DATA-xchpf.
    bapi_marc1-qm_authgrp = 'X'.
    bapi_marcx-qm_authgrp = 'X'.
    BAPI_MARCX-PLANT = IT_DATA-WERKS.
    BAPI_MARCX-PUR_GROUP = 'X'.
    BAPI_MARCX-LOADINGGRP = 'X'.
    BAPI_MARCX-PROFIT_CTR = 'X'.
    BAPI_MARCX-BATCH_MGMT = 'X'.
    * Accounting
    BAPI_MBEW1-VAL_AREA = IT_DATA-WERKS.
    BAPI_MBEW1-PRICE_CTRL = IT_DATA-VPRSV.
    BAPI_MBEW1-STD_PRICE = IT_DATA-STPRS.
    BAPI_MBEW1-PRICE_UNIT = IT_DATA-PEINH.
    BAPI_MBEWX-VAL_AREA = IT_DATA-WERKS.
    BAPI_MBEWX-PRICE_CTRL = 'X'.
    BAPI_MBEWX-STD_PRICE = 'X'.
    BAPI_MBEWX-PRICE_UNIT = 'X'.
    * Sales Data
    BAPI_MVKE1-ITEM_CAT = IT_DATA-MTPOS_MARA.
    BAPI_MVKEX-ITEM_CAT = 'X'.
    BAPI_MVKE1-SALES_ORG = IT_DATA-vkorg.
    BAPI_MVKEX-SALES_ORG = IT_DATA-vkorg.
    BAPI_MVKE1-DISTR_CHAN = IT_DATA-vtweg.
    BAPI_MVKEX-DISTR_CHAN = IT_DATA-vtweg.
    BAPI_MVKE1-MAT_PR_GRP = IT_DATA-kondm.
    BAPI_MVKEX-MAT_PR_GRP = 'X'.
    BAPI_MVKE1-ACCT_ASSGT = IT_DATA-ktgrm.
    BAPI_MVKEX-ACCT_ASSGT = 'X'.
    BAPI_MVKE1-MATL_GRP_1 = IT_DATA-mvgr1.
    BAPI_MVKEX-MATL_GRP_1 = 'X'.
    BAPI_MVKE1-MATL_GRP_2 = IT_DATA-mvgr2.
    BAPI_MVKEX-MATL_GRP_2 = 'X'.
    BAPI_MVKE1-MATL_GRP_3 = IT_DATA-mvgr3.
    BAPI_MVKEX-MATL_GRP_3 = 'X'.
    BAPI_MVKE1-matl_stats = IT_DATA-versg.
    BAPI_MVKEX-matl_stats = 'X'.
    
    
    *--- BAPI to create material
    call function 'BAPI_MATERIAL_SAVEDATA'
    exporting
    HEADDATA = BAPI_HEAD
    CLIENTDATA = BAPI_MARA1
    CLIENTDATAX = BAPI_MARAX
    PLANTDATA = BAPI_MARC1
    PLANTDATAX = BAPI_MARCX
    * FORECASTPARAMETERS =
    * FORECASTPARAMETERSX =
    * PLANNINGDATA =
    * PLANNINGDATAX =
    * STORAGELOCATIONDATA =
    * STORAGELOCATIONDATAX =
    * VALUATIONDATA = BAPI_MBEW1
    * VALUATIONDATAX = BAPI_MBEWX
    * WAREHOUSENUMBERDATA =
    * WAREHOUSENUMBERDATAX =
     SALESDATA = BAPI_MVKE1
     SALESDATAX = BAPI_MVKEX
    * STORAGETYPEDATA =
    * STORAGETYPEDATAX =
    IMPORTING
    RETURN = BAPI_RETURN
    TABLES
    MATERIALDESCRIPTION = IT_MAKT
    * UNITSOFMEASURE =
    * UNITSOFMEASUREX =
    * INTERNATIONALARTNOS =
    * MATERIALLONGTEXT =
    * TAXCLASSIFICATIONS =
    * RETURNMESSAGES =
    * PRTDATA =
    * PRTDATAX =
    * EXTENSIONIN =
    * EXTENSIONINX =
    .
    
    IF BAPI_RETURN-TYPE = 'E'.
    WRITE:/ 'Error:' ,BAPI_RETURN-MESSAGE ,'for material:' ,it_data-matnr.
    ELSEIF BAPI_RETURN-TYPE = 'S'.
    WRITE: 'Successfully created/Changed material' ,it_data-matnr.
          CLEAR return.
          REFRESH return.
          CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
               IMPORTING
                    return = return.
    ENDIF.
    ENDLOOP.
    
    ENDFORM. " UPLOAD_MATMAS
    
    Please do not allocate any points as this is not my code. However I have tested it & it works fine.
    
    Regards
    Raju Chitale
    
    

     

  • Re: Material master uploading using BAPI's
    Siva Sankara Reddy Dondeti
    Currently Being Moderated

    Hi,

     

    you can upload data from XL to SAP like below.

     

     

      CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

        EXPORTING

          filename                = p_fname

          i_begin_col             = '1'

          i_begin_row             = '1'

          i_end_col               = '100'

          i_end_row               = '65000'

        TABLES

          intern                  = i_excel

        EXCEPTIONS

          inconsistent_parameters = 1

          upload_ole              = 2

          OTHERS                  = 3.

      IF sy-subrc eq 0.

        LOOP AT i_excel.

          CASE i_excel-col.

            WHEN 0001.

              wa_final-field1 = i_excel-value.

            WHEN 0002.

              wa_final-field2  = i_excel-value.

            WHEN 0003.

              wa_final-field3  = i_excel-value.

            WHEN 0004.

              wa_final-field4  = i_excel-value.

            WHEN 0005.

              wa_final-field5  = i_excel-value.

            WHEN 0006.

              wa_final-field6 = i_excel-value.

            WHEN 0007.

              wa_final-field7  = i_excel-value.

            WHEN 0008.

              wa_final-field8  = i_excel-value.

            WHEN 0009.

              wa_final-field9  = i_excel-value.

            WHEN 0010.

              wa_final-field10  = i_excel-value.

            WHEN 0011.

              wa_final-field11  = i_excel-value.

            WHEN 0012.

              wa_final-field12  = i_excel-value.

            WHEN 0013.

              wa_final-field13  = i_excel-value.

            WHEN 0014.

              wa_final-field14  = i_excel-value.

            WHEN 0015.

              wa_final-field15  = i_excel-value.

            WHEN 0016.

              wa_final-field16  = i_excel-value.

          ENDCASE.

    *-at end of each row, a record needs to append the internal table

          AT END OF row.

            APPEND wa_final TO i_final.

            CLEAR: wa_final.

          ENDAT.

        ENDLOOP.

      ENDIF.

     

    After this you can use below FM to save Material Data

     

    &----


    *&      Form  MOVE_HEADDATA

    &----


    •    * Move Header data to BAPI Header.

    ----


    FORM move_headdata .

    • Move Header Data to BAPI Fields

      MOVE : wa_final-matnr      TO wa_mathead-material,

             wa_final-mbrsh      TO wa_mathead-ind_sector,

             wa_final-mtart      TO wa_mathead-matl_type.

      • To get UOM

      SELECT SINGLE * FROM t006 INTO t006 WHERE msehi = wa_final-meins.

      MOVE: t006-isocode TO wa_mara-base_uom_iso,

            c_x          TO wa_marax-base_uom_iso.

    **-- Move Material Descriptions

      PERFORM move_materialdescription .

    ENDFORM.                    " MOVE_HEADDATA

    &----


    *&      Form  MOVE_CLIENTDATA

    &----


    •       * Move Basic data to Clientdata

    ----


    FORM   move_clientdata .

      MOVE : wa_final-spart      TO wa_mara-division,

             wa_final-bismt      TO wa_mara-old_mat_no,

             wa_final-extwg      TO wa_mara-extmatlgrp,

             wa_final-mtpos_mara TO wa_mara-item_cat,

             wa_final-groes      TO wa_mara-size_dim,

             wa_final-zeivr      TO wa_mara-doc_vers,

             wa_final-ekwsl      TO wa_mara-pur_valkey.

     

     

      MOVE : c_x      TO wa_marax-division,

             c_x      TO wa_marax-old_mat_no,

             c_x      TO wa_marax-extmatlgrp,

             c_x      TO wa_marax-item_cat,

             c_x      TO wa_marax-size_dim,

             c_x      TO wa_marax-doc_vers,

             c_x      TO wa_marax-pur_valkey.

     

    ENDFORM.                    " MOVE_CLIENTDATA

     

     

    &----


    *&      Form  MOVE_STORAGELOCATIONDATA

    &----


    •       * Move storage location data to STORAGELOCATIONDATA

    ----


    FORM move_storagelocationdata .

      CLEAR: wa_mard,wa_mardx.

     

      MOVE : wa_final-werks      TO wa_mard-plant,

             wa_final-lgort      TO wa_mard-stge_loc.

     

     

      MOVE : wa_final-werks      TO wa_mardx-plant,

             wa_final-lgort      TO wa_mardx-stge_loc.

     

    ENDFORM.                    " MOVE_STORAGELOCATIONDATA

    &----


    *&      Form  MOVE_SALESDATA

    &----


    •      * Move Salesdate to SALESDATA

    ----


    FORM move_salesdata .

      CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'

        EXPORTING

          input          = wa_final-vrkme

        IMPORTING

          output         = wa_final-vrkme

        EXCEPTIONS

          unit_not_found = 1

          OTHERS         = 2.

      IF sy-subrc <> 0.

        wa_final-vrkme = wa_final-vrkme.

      ENDIF.

      MOVE : wa_final-vkorg      TO wa_mvke-sales_org,

             wa_final-vtweg      TO wa_mvke-distr_chan,

             wa_final-dwerk      TO wa_mvke-delyg_plnt,

             wa_final-versg      TO wa_mvke-matl_stats,

             wa_final-ktgrm      TO wa_mvke-acct_assgt,

             wa_final-mtpos      TO wa_mvke-item_cat,

             wa_final-mvgr1      TO wa_mvke-matl_grp_1,

             wa_final-mvgr2      TO wa_mvke-matl_grp_2,

             wa_final-mvgr3      TO wa_mvke-matl_grp_3,

             wa_final-mvgr4      TO wa_mvke-matl_grp_4,

             wa_final-mvgr5      TO wa_mvke-matl_grp_5,

             wa_final-vrkme      TO wa_mvke-sales_unit.

     

      MOVE : wa_final-vkorg      TO wa_mvkex-sales_org,

             wa_final-vtweg      TO wa_mvkex-distr_chan,

             c_x                 TO wa_mvkex-delyg_plnt,

             c_x                 TO wa_mvkex-matl_stats,

             c_x                 TO wa_mvkex-acct_assgt,

             c_x                 TO wa_mvkex-item_cat,

             c_x                 TO wa_mvkex-matl_grp_1,

             c_x                 TO wa_mvkex-matl_grp_2,

             c_x                 TO wa_mvkex-matl_grp_3,

             c_x                 TO wa_mvkex-matl_grp_4,

             c_x                 TO wa_mvkex-matl_grp_5,

             c_x                 TO wa_mvkex-sales_unit.

     

    ENDFORM.                    " MOVE_SALESDATA

    &----


    *&      Form  MOVE_MATERIALDESCRIPTION

    &----


    •       * Move MATERIALDESCRIPTION to Material Description

    ----


    FORM move_materialdescription .

      CLEAR: wa_makt,i_makt.

     

      MOVE : wa_final-maktx TO wa_makt-matl_desc,

             sy-langu       TO wa_makt-langu.

      APPEND wa_makt TO i_makt.

      CLEAR wa_makt.

    ENDFORM.                    " MOVE_MATERIALDESCRIPTION

    &----


    *&      Form  basic_data

    &----


    FORM basic_data .

    **-- Move Material Data at Storage Location Level

      PERFORM move_storagelocationdata .

      MOVE : wa_final-vkorg      TO wa_mvke-sales_org,

             wa_final-vtweg      TO wa_mvke-distr_chan.

      MOVE : wa_final-vkorg      TO wa_mvkex-sales_org,

             wa_final-vtweg      TO wa_mvkex-distr_chan.

    **-- Move Material Data at Client Level

      PERFORM move_clientdata .

    • IF ALT_UOM is not Given in flat file Move BASEUOM as ALT_UOM

      IF wa_final-meinh EQ c_space.

        MOVE : wa_final-meins     TO wa_marm-alt_unit,

               wa_final-meins     TO wa_marmx-alt_unit.

      ELSE.

        MOVE : wa_final-meinh      TO wa_marm-alt_unit,

                wa_final-umren      TO wa_marm-numerator.

     

        MOVE : wa_final-meinh     TO wa_marmx-alt_unit,

               c_x                TO wa_marmx-numerator.

     

      ENDIF.

     

      MOVE : wa_final-numtp      TO wa_marm-ean_cat,

             wa_final-brgew      TO wa_marm-gross_wt,

             wa_final-volum      TO wa_marm-volume,

             wa_final-voleh      TO wa_marm-volumeunit,

             wa_final-gewei      TO wa_marm-unit_of_wt.

      APPEND wa_marm TO i_marm.

      CLEAR wa_marm.

     

      MOVE : c_x                TO wa_marmx-ean_cat,

             c_x                TO wa_marmx-gross_wt,

             c_x                TO wa_marmx-volume,

             c_x                TO wa_marmx-volumeunit,

             c_x                TO wa_marmx-unit_of_wt.

      APPEND wa_marmx TO i_marmx.

      CLEAR wa_marmx.

     

    ENDFORM.                    " basic_data

    &----


    *&      Form  sales_data1

    &----


    FORM sales_data1 .

    • Move Sales & Plant Data

      MOVE : wa_final-werks      TO wa_marc-plant,

             wa_final-mtvfp      TO wa_marc-availcheck,

             wa_final-ladgr      TO wa_marc-loadinggrp,

             wa_final-prctr      TO wa_marc-profit_ctr.

      MOVE : wa_final-werks      TO wa_marcx-plant,

             c_x                 TO wa_marcx-availcheck,

             c_x                 TO wa_marcx-loadinggrp,

             c_x                 TO wa_marcx-profit_ctr.

      MOVE: wa_final-tragr      TO wa_mara-trans_grp,

            c_x                 TO wa_marax-trans_grp.

    **-- Move Sales Data

      PERFORM move_salesdata .

     

    • Move Tax Data

      MOVE : 'JP'              TO wa_mlan-depcountry_iso,

            'MWAR'             TO wa_mlan-tax_type_1,

             wa_final-taklv    TO wa_mlan-taxclass_1.

      APPEND wa_mlan TO i_mlan.

      CLEAR wa_mlan.

     

     

    ENDFORM.                    " sales_data1

    &----


    *&      Form  purchase_data

    &----


    FORM purchase_data .

     

    • Move Plant Data

      MOVE : wa_final-werks      TO wa_marc-plant,

             wa_final-werks      TO wa_marcx-plant.

    • Move PO data

      MOVE : wa_final-ekgrp  TO wa_marc-pur_group,

             wa_final-kautb  TO wa_marc-auto_p_ord,

             wa_final-usequ  TO wa_marc-quotausage,

             wa_final-kordb  TO wa_marc-sourcelist,

             c_x             TO wa_marcx-pur_group,

             c_x             TO wa_marcx-auto_p_ord,

             c_x             TO wa_marcx-quotausage,

             c_x             TO wa_marcx-sourcelist.

     

      MOVE: wa_final-matkl  TO wa_mara-matl_group,

            wa_final-bstme  TO wa_mara-po_unit,

             c_x            TO wa_marax-matl_group,

             c_x            TO wa_marax-po_unit.

     

    ENDFORM.                    " purchase_data

    &----


    *&      Form  mrp_data

    &----


    FORM mrp_data .

    **-- Move Material Data at Storage Location Level

      PERFORM move_storagelocationdata .

    • Move All MRP data

      MOVE: wa_final-diskz TO wa_mard-mrp_ind,

            c_x            TO wa_mardx-mrp_ind.

      MOVE : wa_final-werks TO wa_marc-plant,

             wa_final-dismm TO wa_marc-mrp_type,

             wa_final-dispo TO wa_marc-mrp_ctrler,

             wa_final-beskz TO wa_marc-proc_type,

             wa_final-sobsl TO wa_marc-spproctype,

             wa_final-mtvfp TO wa_marc-availcheck,

             wa_final-minbe  TO wa_marc-reorder_pt,

             wa_final-fxhor  TO wa_marc-pl_ti_fnce,

             wa_final-disls  TO wa_marc-lotsizekey,

             wa_final-bstmi  TO wa_marc-minlotsize,

             wa_final-bstma  TO wa_marc-maxlotsize,

             wa_final-bstfe  TO wa_marc-fixed_lot,

             wa_final-mabst  TO wa_marc-max_stock,

             wa_final-ausss  TO wa_marc-assy_scrap,

             wa_final-dzeit  TO wa_marc-inhseprodt,

             wa_final-plifz  TO wa_marc-plnd_delry,

             wa_final-webaz  TO wa_marc-gr_pr_time,

             wa_final-fhori  TO wa_marc-sm_key,

             wa_final-eisbe  TO wa_marc-safety_stk,

             wa_final-strgr  TO wa_marc-plan_strgp,

             wa_final-wzeit  TO wa_marc-replentime,

             wa_final-lgfsb  TO wa_marc-sloc_exprc,

             wa_final-sbdkz  TO wa_marc-dep_req_id,

             wa_final-kzbed  TO wa_marc-grp_reqmts,

             wa_final-miskz  TO wa_marc-mixed_mrp,

             wa_final-stlal  TO wa_marc-alternative_bom,

             wa_final-stlan  TO wa_marc-bom_usage.

     

      MOVE : wa_final-werks TO wa_marcx-plant,

             c_x            TO wa_marcx-mrp_type,

             c_x            TO wa_marcx-mrp_ctrler,

             c_x            TO wa_marcx-proc_type,

             c_x            TO wa_marcx-spproctype,

             c_x            TO wa_marcx-availcheck,

             c_x            TO wa_marcx-reorder_pt,

             c_x            TO wa_marcx-pl_ti_fnce,

             c_x            TO wa_marcx-lotsizekey,

             c_x            TO wa_marcx-minlotsize,

             c_x            TO wa_marcx-maxlotsize,

             c_x            TO wa_marcx-fixed_lot,

             c_x            TO wa_marcx-max_stock,

             c_x            TO wa_marcx-assy_scrap,

             c_x            TO wa_marcx-inhseprodt,

             c_x            TO wa_marcx-plnd_delry,

             c_x            TO wa_marcx-gr_pr_time,

             c_x            TO wa_marcx-sm_key,

             c_x            TO wa_marcx-safety_stk,

             c_x            TO wa_marcx-plan_strgp,

             c_x            TO wa_marcx-replentime,

             c_x            TO wa_marcx-sloc_exprc,

             c_x            TO wa_marcx-dep_req_id,

             c_x            TO wa_marcx-grp_reqmts,

             c_x            TO wa_marcx-mixed_mrp,

             c_x            TO wa_marcx-alternative_bom,

             c_x            TO wa_marcx-bom_usage.

     

    ENDFORM.                    " mrp_data

    &----


    *&      Form  accounting_data

    &----


    FORM accounting_data .

    • Move Plant Data

      MOVE: wa_final-werks TO wa_marc-plant,

            wa_final-werks TO wa_marcx-plant.

     

    • Move Account Data

      MOVE :  wa_final-werks TO wa_mbew-val_area,

              wa_final-bklas TO wa_mbew-val_class,

              wa_final-vprsv TO wa_mbew-price_ctrl,

              wa_final-verpr TO wa_mbew-moving_pr,

              wa_final-peinh TO wa_mbew-price_unit,

              wa_final-stprs TO wa_mbew-std_price.

     

      MOVE :  wa_final-werks TO wa_mbewx-val_area,

              c_x TO wa_mbewx-val_class,

              c_x TO wa_mbewx-price_ctrl,

              c_x TO wa_mbewx-moving_pr,

              c_x TO wa_mbewx-price_unit,

              c_x TO wa_mbewx-std_price.

     

    ENDFORM.                    " accounting_data

    &----


    *&      Form  cost_data

    &----


    FORM cost_data .

    • Move Plant Data

      MOVE: wa_final-werks TO wa_marc-plant,

            wa_final-awsls TO wa_marc-variance_key,

            wa_final-verid  TO wa_marc-prodverscs,   " Production Version

            wa_final-werks TO wa_marcx-plant,

            c_x            TO wa_marcx-variance_key,

            c_x            TO wa_marcx-prodverscs.

    • Move Cost Data

      MOVE :  wa_final-werks TO wa_mbew-val_area,

              wa_final-bklas TO wa_mbew-val_class,

              wa_final-vprsv TO wa_mbew-price_ctrl,

              wa_final-ekalr TO wa_mbew-qty_struct.

     

      MOVE :  wa_final-werks TO wa_mbewx-val_area,

              c_x            TO wa_mbewx-val_class,

              c_x            TO wa_mbewx-price_ctrl,

              c_x            TO wa_mbewx-qty_struct.

     

      CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'

        EXPORTING

          headdata             = wa_mathead

          clientdata           = wa_mara

          clientdatax          = wa_marax

          plantdata            = wa_marc

          plantdatax           = wa_marcx

          storagelocationdata  = wa_mard

          storagelocationdatax = wa_mardx

          valuationdata        = wa_mbew

          valuationdatax       = wa_mbewx

          salesdata            = wa_mvke

          salesdatax           = wa_mvkex

        IMPORTING

          return               = i_return

        TABLES

          materialdescription  = i_makt

          unitsofmeasure       = i_marm

          unitsofmeasurex      = i_marmx

          taxclassifications   = i_mlan.

     

      IF i_return-type = 'A' OR i_return-type = 'E' .

        DATA : l_v_string TYPE string,

               l_v_msg1   TYPE string,

               l_v_msg2   TYPE string.

        MOVE i_return-message TO l_v_string.

        CONDENSE l_v_string.

        PERFORM fill_error_table USING 'E'

                                       'ZMSG_MM'

                                       '098'

                                       v_reccon

                                       l_v_string

                                       ''

                                       ''.

        v_error = v_error + 1.

        CLEAR: l_v_string.

      ELSEIF i_return-type = 'S'.

        PERFORM fill_error_table USING 'S'

                                             i_return-id

                                             i_return-number

                                            i_return-message_v1

                                           i_return-message_v2

                                           i_return-message_v3

                                           i_return-message_v4.

     

        v_success = v_success + 1.

     

      ENDIF .

      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

        EXPORTING

          wait = 'X'.

      IF sy-subrc = 0.

        COMMIT WORK AND WAIT.      "for the update to table Transcation

      ENDIF.

     

    Regards,

    Siva.

  • Re: Material master uploading using BAPI's
    Murugesh P
    Currently Being Moderated

    Thank you for all

Actions