Quantcast
Channel: SCN : Document List - ABAP Development
Viewing all articles
Browse latest Browse all 935

BAPI for Material Master Upload program

$
0
0

Dear,

I am posting a document on material master (MM01) upload program through BAPI. Its Very important and Common for SAP implementation Project.

 

 

************************************************************************

*                PROGRAM INFORMATION

************************************************************************

*  PROGRAM....... ZMM_MM01_BAPI

*  TITLE......... MATERIAL MASTER UPLOAD

*  AUTHOR........ SABYASACHI KARFORMA

* FUNCTIONAL....

* START DATE.... 26/07/2013

* END DATE.......26/07/2013

* DEV.CLASS......ZMM

* TCODE..........ZMM01

*  R/3 RELEASE....SAP ECC 6.0

*  TRANSPORTNR... AEDK900403

*  COPIED FROM... N/A

*---------------------------------------------------------------------

*                PROGRAM FUNCTION:

* This conversion program is to Upload MATERIAL MASTER.

*---------------------------------------------------------------------

*  PROGRAM TYPE.. Executable

*  LOGICAL DB.... N/A

************************************************************************

 

************************************************************************

*                CHANGE HISTORY

************************************************************************

*  DATE CHANGE... <Date of change written>

*  AUTHOR........ <Author name>

*  CHANGE DESCR.. <Description of change>

*  R/3 RELEASE... <Release>

*  TRANSPORTNR... <Transport number>

************************************************************************

************************************************************************

REPORT ZMM_MM01_BAPI.

 

TYPE-POOLS : truxs.

 

TYPES: BEGIN OF TY_MARA,

        INT_NUM TYPE I,

        MTART TYPE MTART,

        WERKS TYPE WERKS_D,

        VKORG TYPE VKORG,

        VTWEG TYPE VTWEG,

        MAKTX TYPE MAKTX,

        MEINS TYPE MEINS,

        MATKL TYPE MATKL,

        BISMT TYPE BISMT,

        SPART TYPE SPART,

        VERSG LIKE MVKE-VERSG,

        KONDM LIKE MVKE-KONDM,

        KTGRM LIKE MVKE-KTGRM,

        MTPOS LIKE MVKE-MTPOS,

        MTVFP LIKE MARC-MTVFP,

        TRAGR LIKE MARA-TRAGR,

        LADGR LIKE MARC-LADGR,

        PRCTR TYPE PRCTR,

        EKWSL LIKE MARA-EKWSL,

        TDLINE TYPE TDLINE,

        DISMM LIKE MARC-DISMM,

        PLIFZ LIKE MARC-PLIFZ,

        WEBAZ LIKE MARC-WEBAZ,

        MHDRZ LIKE MARA-MHDRZ,

        MHDHB LIKE MARA-MHDHB,

        IPRKZ LIKE MARA-IPRKZ,

        BKLAS LIKE MBEW-BKLAS,

        VERPR LIKE MBEW-VERPR,

        END OF TY_MARA.

 

TYPES: BEGIN OF TY_ITEM,

        INT_NUM TYPE I,

        UMREN TYPE SMEINH-UMREN,

        MEINH TYPE SMEINH-MEINH,

        UMREZ TYPE SMEINH-UMREZ,

        END OF TY_ITEM.

 

DATA: IT_MARA TYPE STANDARD TABLE OF TY_MARA,

       WA_MARA TYPE TY_MARA.

 

DATA: IT_ITEM TYPE STANDARD TABLE OF TY_ITEM,

       WA_ITEM TYPE TY_ITEM.

 

DATA: IT_EXCEL TYPE STANDARD TABLE OF ALSMEX_TABLINE,

       WA_EXCEL TYPE ALSMEX_TABLINE.

data: it TYPE STANDARD TABLE OF BAPIMATINR,

       WA TYPE BAPIMATINR.

DATA: GV_MTART TYPE BAPIMATDOA-MATL_TYPE,

       GV_MBRSH TYPE BAPIMATDOA-IND_SECTOR.

 

DATA: LC_X type C VALUE 'X'.

DATA: GV_SRNO TYPE I.

 

data LWA_HEADDATA LIKE BAPIMATHEAD,

         lwa_CLIENTDATA type BAPI_MARA,

         lwa_CLIENTDATAX type BAPI_MARAX,

         lwa_PLANTDATA type  BAPI_MARC,

         lwa_PLANTDATAX type  BAPI_MARCX,

         lwa_STORAGELOCATIONDATA type  BAPI_MARD,

         lwa_STORAGELOCATIONDATAX type  BAPI_MARDX,

         lwa_VALUATIONDATA type  BAPI_MBEW,

         lwa_VALUATIONDATAX type  BAPI_MBEWX,

         lwa_SALESDATA type  BAPI_MVKE,

         lwa_SALESDATAX type  BAPI_MVKEX,

         lwa_return type BAPIRET2.

 

***************** INTERNAL TABLE DECLARATION*****************

 

data:   li_MATERIALDESCRIPTION type table of BAPI_MAKT,

         li_UNITSOFMEASURE TYPE TABLE OF BAPI_MARM,

         LI_INTERNATIONALARTNOS TYPE TABLE OF BAPI_MEAN,

         li_UNITSOFMEASUREX type table of BAPI_MARMX,

         li_MATERIALLONGTEXT type table of BAPI_MLTX,

         li_returnmessages type TABLE OF BAPI_MATRETURN2.

 

***************** WORK AREA DECLARATION*****************

 

data:   lwa_UNITSOFMEASURE type  BAPI_MARM,

         LWA_INTERNATIONALARTNOS TYPE BAPI_MEAN,

         LWA_MATERIALDESCRIPTION TYPE BAPI_MAKT,

         LWA_UNITSOFMEASUREX TYPE BAPI_MARMX,

         lwa_MATERIALLONGTEXT type  BAPI_MLTX,

         LWA_returnmessages TYPE BAPI_MATRETURN2.

 

************** SELECTION SCREEN**************

 

SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

PARAMETERS : P_FILE TYPE LOCALFILE,

              BEG_COL TYPE I DEFAULT '1' NO-DISPLAY,

              END_COL TYPE I DEFAULT '31' NO-DISPLAY,

              BEG_ROW TYPE I DEFAULT '3' NO-DISPLAY,

              END_ROW TYPE I DEFAULT '32000' NO-DISPLAY.

SELECTION-SCREEN: END OF BLOCK B1.

 

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

   CALL FUNCTION 'F4_FILENAME'

    EXPORTING

      PROGRAM_NAME        = SYST-CPROG

      DYNPRO_NUMBER       = SYST-DYNNR

*     FIELD_NAME          = ' '

    IMPORTING

      FILE_NAME           = P_FILE

             .

 

 

start-of-selection.

 

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

   EXPORTING

     filename                      = P_FILE

     i_begin_col                   = BEG_COL

     i_begin_row                   = BEG_ROW

     i_end_col                     = END_COL

     i_end_row                     = END_ROW

   TABLES

     intern                        = IT_EXCEL

  EXCEPTIONS

    INCONSISTENT_PARAMETERS       = 1

    UPLOAD_OLE                    = 2

    OTHERS                        = 3

           .

IF sy-subrc EQ 0.

* Implement suitable error handling here

 

************  EXCEL TO INTERNAL TABLE MAPPING ************

 

  LOOP AT IT_EXCEL INTO WA_EXCEL.

    CASE WA_EXCEL-COL.

      WHEN '0001'.

        WA_MARA-INT_NUM = WA_EXCEL-VALUE.

        WA_ITEM-INT_NUM WA_EXCEL-VALUE.

       WHEN '0002'.

        WA_MARA-MTART = WA_EXCEL-VALUE.

       WHEN '0003'.

        WA_MARA-WERKS = WA_EXCEL-VALUE.

         WHEN '0004'.

        WA_MARA-VKORG = WA_EXCEL-VALUE.

         WHEN '0005'.

        WA_MARA-VTWEG = WA_EXCEL-VALUE.

         WHEN '0006'.

        WA_MARA-MAKTX = WA_EXCEL-VALUE.

         WHEN '0007'.

        WA_MARA-MEINS = WA_EXCEL-VALUE.

         WHEN '0008'.

        WA_MARA-MATKL = WA_EXCEL-VALUE.

         WHEN '0009'.

        WA_MARA-BISMT = WA_EXCEL-VALUE.

         WHEN '0010'.

        WA_MARA-SPART = WA_EXCEL-VALUE.

         WHEN '0011'.

        WA_ITEM-MEINH = WA_EXCEL-VALUE.

        WHEN '0012'.

        WA_ITEM-UMREN = WA_EXCEL-VALUE.

        WHEN '0013'.

        WA_ITEM-UMREZ = WA_EXCEL-VALUE.

        WHEN '0014'.

        WA_MARA-VERSG = WA_EXCEL-VALUE.

        WHEN '0015'.

        WA_MARA-KONDM = WA_EXCEL-VALUE.

        WHEN '0016'.

        WA_MARA-KTGRM = WA_EXCEL-VALUE.

        WHEN '0017'.

        WA_MARA-MTPOS = WA_EXCEL-VALUE.

        WHEN '0018'.

        WA_MARA-MTVFP = WA_EXCEL-VALUE.

        WHEN '0019'.

        WA_MARA-TRAGR = WA_EXCEL-VALUE.

        WHEN '0020'.

        WA_MARA-LADGR = WA_EXCEL-VALUE.

        WHEN '0021'.

        WA_MARA-PRCTR = WA_EXCEL-VALUE.

        WHEN '0022'.

        WA_MARA-EKWSL = WA_EXCEL-VALUE.

        WHEN '0023'.

        WA_MARA-TDLINE = WA_EXCEL-VALUE.

        WHEN '0024'.

        WA_MARA-DISMM = WA_EXCEL-VALUE.

        WHEN '0025'.

        WA_MARA-PLIFZ = WA_EXCEL-VALUE.

        WHEN '0026'.

        WA_MARA-WEBAZ = WA_EXCEL-VALUE.

        WHEN '0027'.

        WA_MARA-MHDRZ = WA_EXCEL-VALUE.

        WHEN '0028'.

        WA_MARA-MHDHB = WA_EXCEL-VALUE.

        WHEN '0029'.

        WA_MARA-IPRKZ = WA_EXCEL-VALUE.

        WHEN '0030'.

        WA_MARA-BKLAS = WA_EXCEL-VALUE.

        WHEN '0031'.

        WA_MARA-VERPR  = WA_EXCEL-VALUE.

        ENDCASE.

 

        AT END OF ROW.

          APPEND WA_MARA TO IT_MARA.

          APPEND WA_ITEM TO IT_ITEM.

 

          CLEAR WA_MARA.

          CLEAR WA_EXCEL.

          CLEAR WA_ITEM.

        ENDAT.

        ENDLOOP.

ENDIF.

 

 

 

LOOP AT IT_MARA INTO WA_MARA.

   IF GV_SRNO EQ WA_MARA-INT_NUM.

     CONTINUE.

   ENDIF.

 

   GV_SRNO = WA_MARA-INT_NUM.

   if sy-subrc eq 0.

     TRANSLATE WA_MARA-MTART TO UPPER CASE.

     GV_MTART = WA_MARA-MTART.

     GV_MBRSH = 'A'.

 

   CALL FUNCTION 'BAPI_MATERIAL_GETINTNUMBER'

     EXPORTING

       material_type          = GV_MTART

      INDUSTRY_SECTOR        = GV_MBRSH

*     REQUIRED_NUMBERS       = 1

*   IMPORTING

*     RETURN                 =

     tables

       material_number        = it

             .

 

   ENDIF.

   IF IT IS NOT INITIAL.

   READ TABLE IT INTO WA INDEX 1.

lwa_headdata-MATERIAL = WA-material.

CLEAR IT.

CLEAR WA.

    ENDIF.

lwa_headdata-ind_sector = 'A'.

lwa_headdata-matl_type = wa_mara-mtart.

lwa_headdata-basic_view = lc_x.

lwa_headdata-sales_view = lc_x.

lwa_headdata-purchase_view = lc_x.

lwa_headdata-mrp_view = lc_x.

lwa_headdata-storage_view lc_x.

lwa_headdata-account_view = lc_x.

 

*

lwa_materialdescription-LANGU  = 'E'.

lwa_materialdescription-LANGU_ISO = 'EN'.

lwa_materialdescription-MATL_DESC = wa_mara-maktx.

 

append lwa_materialdescription to li_materialdescription.

 

 

***********************SALES DATA**********************

 

 

 

lwa_salesdata-sales_org = wa_mara-vkorg.

TRANSLATE wa_mara-vtweg TO UPPER CASE.

lwa_salesdata-distr_chan = wa_mara-vtweg.

lwa_salesdata-matl_stats = wa_mara-versg.

TRANSLATE wa_mara-mtpos TO UPPER CASE.

lwa_salesdata-item_cat = wa_mara-mtpos.

lwa_salesdata-mat_pr_grp wa_mara-kondm.

lwa_salesdata-acct_assgt = wa_mara-ktgrm.

 

lwa_salesdatax-sales_org = wa_mara-vkorg.

lwa_salesdatax-distr_chan = wa_mara-vtweg.

lwa_salesdatax-matl_stats = lc_x.

lwa_salesdatax-item_cat = lc_x.

lwa_salesdatax-mat_pr_grp lc_x.

lwa_salesdatax-acct_assgt = lc_x.

 

 

******************CLIENT DATA*****************

 

 

lwa_clientdata-matl_group = wa_mara-matkl.

lwa_clientdata-old_mat_no = wa_mara-bismt.

lwa_clientdata-division = wa_mara-spart.

TRANSLATE wa_mara-meins TO UPPER CASE.

lwa_clientdata-base_uom = wa_mara-meins.

lwa_clientdata-trans_grp = wa_mara-tragr.

lwa_clientdata-minremlife = wa_mara-mhdrz.

lwa_clientdata-shelf_life  = wa_mara-mhdhb.

 

TRANSLATE  wa_mara-iprkz TO UPPER CASE.

 

CALL FUNCTION 'CONVERSION_EXIT_PERKZ_INPUT'

   EXPORTING

     input         = wa_mara-iprkz

  IMPORTING

    OUTPUT        = lwa_clientdata-PERIOD_IND_EXPIRATION_DATE

           .

lwa_clientdata-PUR_VALKEY = wa_mara-ekwsl.

 

lwa_clientdatax-matl_group = lc_x.

lwa_clientdatax-old_mat_no = lc_x.

lwa_clientdatax-division = lc_x.

lwa_clientdatax-base_uom = lc_x.

lwa_clientdatax-trans_grp = lc_x.

lwa_clientdatax-minremlife = lc_x.

lwa_clientdatax-shelf_life  = lc_x.

lwa_clientdatax-PERIOD_IND_EXPIRATION_DATE = lc_x.

lwa_clientdatax-PUR_VALKEY = lc_x.

 

***************** Plant data ******************************

 

TRANSLATE WA_MARA-werks  TO UPPER CASE.

lwa_plantdata-plant = WA_MARA-werks .

lwa_plantdata-LOADINGGRP = WA_MARA-ladgr.

TRANSLATE WA_MARA-dismm TO UPPER CASE.

lwa_plantdata-MRP_TYPE = WA_MARA-dismm .

lwa_plantdata-PLND_DELRY = WA_MARA-plifz.

TRANSLATE WA_MARA-mtvfp TO UPPER CASE.

lwa_plantdata-AVAILCHECK = WA_MARA-mtvfp.

lwa_plantdata-GR_PR_TIME = WA_MARA-WEBAZ.

 

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

   EXPORTING

     input         = wa_mara-prctr

  IMPORTING

    OUTPUT        lwa_plantdata-PROFIT_CTR

           .

 

lwa_plantdatax-plant = WA_MARA-werks.

lwa_plantdatax-LOADINGGRP LC_X.

lwa_plantdatax-MRP_TYPE LC_X.

lwa_plantdatax-PLND_DELRY LC_X.

lwa_plantdatax-AVAILCHECK LC_X.

lwa_plantdatax-PROFIT_CTR = LC_X.

lwa_plantdataX-GR_PR_TIME = LC_X.

 

********************* valuation data ***************************

 

LWA_VALUATIONDATA-VAL_AREA = WA_MARA-WERKS.

lwa_valuationdata-MOVING_PR  = WA_MARA-verpr.

lwa_valuationdata-VAL_CLASS  = WA_MARA-bklas .

 

LWA_VALUATIONDATAX-VAL_AREA = WA_MARA-WERKS.

lwa_valuationdatax-MOVING_PR  = LC_X.

lwa_valuationdatax-VAL_CLASS  = LC_X.

 

******************MATERIAL LONG TEXT******************

 

    lwa_MATERIALLONGTEXT-TEXT_NAME = lwa_headdata-MATERIAL.

    lwa_MATERIALLONGTEXT-APPLOBJECT  = 'MATERIAL'.

    lwa_MATERIALLONGTEXT-TEXT_ID = 'BEST'.

    lwa_MATERIALLONGTEXT-LANGU = 'E'.

    lwa_MATERIALLONGTEXT-LANGU_ISO = 'EN'.

    lwa_MATERIALLONGTEXT-FORMAT_COL = '*'.

    lwa_MATERIALLONGTEXT-TEXT_LINE = WA_MARA-TDLINE.

 

    APPEND lwa_MATERIALLONGTEXT TO LI_MATERIALLONGTEXT.

 

****************UNIT OF MEASURE***************

 

LOOP AT IT_ITEM INTO WA_ITEM WHERE INT_NUM EQ WA_MARA-INT_NUM.

TRANSLATE WA_ITEM-MEINH TO UPPER CASE.

   CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'

     EXPORTING

      input                = WA_ITEM-MEINH

      LANGUAGE             = SY-LANGU

    IMPORTING

      OUTPUT               = LWA_UNITSOFMEASURE-ALT_UNIT

    EXCEPTIONS

      UNIT_NOT_FOUND       = 1

      OTHERS               = 2

             .

 

lwa_UNITSOFMEASURE-DENOMINATR = WA_ITEM-UMREN.

lwa_UNITSOFMEASURE-NUMERATOR WA_ITEM-UMREZ.

APPEND lwa_UNITSOFMEASURE TO   li_UNITSOFMEASURE.

 

TRANSLATE WA_ITEM-MEINH TO UPPER CASE.

 

   CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'

     EXPORTING

       input                = WA_ITEM-MEINH

      LANGUAGE             = SY-LANGU

    IMPORTING

      OUTPUT               = LWA_UNITSOFMEASUREX-ALT_UNIT

    EXCEPTIONS

      UNIT_NOT_FOUND       = 1

      OTHERS               = 2

             .

   IF SY-SUBRC EQ 1.

     MESSAGE 'UNIT NOT FOUND' TYPE 'E'.

   ENDIF.

 

LWA_UNITSOFMEASUREX-DENOMINATR = LC_X.

LWA_UNITSOFMEASUREX-NUMERATOR  = LC_X.

 

APPEND LWA_UNITSOFMEASUREX TO LI_UNITSOFMEASUREX.

 

CLEAR WA_ITEM.

ENDLOOP.

 

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'

   EXPORTING

    headdata                    = LWA_HEADDATA

    CLIENTDATA                  = LWA_CLIENTDATA

    CLIENTDATAX                 = LWA_CLIENTDATAX

    PLANTDATA                   = lwa_PLANTDATA

    PLANTDATAX                  = lwa_PLANTDATAX

*   FORECASTPARAMETERS          =

*   FORECASTPARAMETERSX         =

*   PLANNINGDATA                =

*   PLANNINGDATAX               =

*   STORAGELOCATIONDATA         =

*   STORAGELOCATIONDATAX        =

    VALUATIONDATA               =   lwa_VALUATIONDATA

    VALUATIONDATAX              =   lwa_VALUATIONDATAX

*   WAREHOUSENUMBERDATA         =

*   WAREHOUSENUMBERDATAX        =

    SALESDATA                   lwa_SALESDATA

    SALESDATAX                  lwa_SALESDATAX

*   STORAGETYPEDATA             =

*   STORAGETYPEDATAX            =

*   FLAG_ONLINE                 = ' '

*   FLAG_CAD_CALL               = ' '

*   NO_DEQUEUE                  = ' '

*   NO_ROLLBACK_WORK            = ' '

  IMPORTING

    RETURN                      lwa_return

  TABLES

    MATERIALDESCRIPTION         = li_MATERIALDESCRIPTION

    UNITSOFMEASURE              = LI_UNITSOFMEASURE

    UNITSOFMEASUREX             = LI_UNITSOFMEASUREX

*   INTERNATIONALARTNOS         = LI_INTERNATIONALARTNOS

    MATERIALLONGTEXT            = LI_MATERIALLONGTEXT

*   TAXCLASSIFICATIONS          =

    RETURNMESSAGES              = li_returnmessages

*   PRTDATA                     =

*   PRTDATAX                    =

*   EXTENSIONIN                 =

*   EXTENSIONINX                =

*   NFMCHARGEWEIGHTS            =

*   NFMCHARGEWEIGHTSX           =

*   NFMSTRUCTURALWEIGHTS        =

*   NFMSTRUCTURALWEIGHTSX       =

           .

IF SY-SUBRC EQ 0.

READ TABLE li_returnmessages INTO LWA_returnmessages WITH KEY TYPE = 'E'.

IF SY-SUBRC NE 0.

   CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

    EXPORTING

      WAIT          = 'X'

          .

   ELSEIF SY-SUBRC EQ 0.

     WRITE:/ 'ERROR IS IN SERIAL NO: ' , WA_MARA-INT_NUM , 'IN EXCEL FILE'.

  ENDIF.

 

ENDIF.

   READ TABLE li_returnmessages INTO LWA_returnmessages WITH KEY TYPE = 'S'.

   IF SY-SUBRC EQ 0.

     WRITE:/ 'SERIAL NO',

             15 'MESSAGE TYPE',

               35 'MESSAGE'.

 

WRITE:/ WA_MARA-INT_NUM UNDER 'SERIAL NO',

            18 LWA_returnmessages-TYPE ,"UNDER 'MESSAGE TYPE' ,

              37 LWA_returnmessages-MESSAGE." UNDER  'MESSAGE'.

     ENDIF.

 

     CLEAR LWA_HEADDATA.

     CLEAR LWA_CLIENTDATA.

     CLEAR lwa_PLANTDATA.

     CLEAR LWA_CLIENTDATAX.

     CLEAR lwa_PLANTDATAX.

     CLEAR lwa_VALUATIONDATA.

     CLEAR lwa_VALUATIONDATAX.

     CLEAR lwa_SALESDATA.

     CLEAR lwa_SALESDATAX.

     CLEAR li_MATERIALDESCRIPTION.

     CLEAR LI_UNITSOFMEASURE.

     CLEAR LI_UNITSOFMEASUREX.

     CLEAR LI_MATERIALLONGTEXT.

     CLEAR LWA_MATERIALDESCRIPTION.

     CLEAR LWA_UNITSOFMEASURE.

     CLEAR LWA_UNITSOFMEASUREX.

     CLEAR LWA_MATERIALLONGTEXT.

     CLEAR li_returnmessages.

     CLEAR LWA_returnmessages.

     CLEAR WA_MARA.

ENDLOOP.

 

 

Hope it will be more helpful.

 

 

Regards

Sabyasachi


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>