Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Problem in BAPI_MATERIAL_SAVEDATA

Hi Experts,

I am trying to uplaod the material master data using bapi_material_savedata.

It is working fine for one data, and if i try to upload more datas then the first data getting created and remaining data getting the following error

Field MATNR has been transferred inconsistently or is blank

And the material is created using external number range that is ill give the material number in the excel sheet.

Am pasting the code also here for your reference

Please do the needfull.

Thanks in advance.

REPORT  z_mm_mat_mast_upld.

TYPE-POOLS: slis, truxs.

DATA: wa_tab_raw_data TYPE  truxs_t_text_data,

       sno TYPE i.

TYPES: BEGIN OF ty_msg,

        sno TYPE i,

        msgtyp TYPE c,

        plant(4),

        mstring(255) TYPE c,

        END OF ty_msg.

DATA tmsstab TYPE TABLE OF ty_msg.

DATA wmsstab TYPE ty_msg.

DATA : lv_sno TYPE i.

TABLES : bapimathead, " Header segment with control information

          bapi_mara,   " Client-specific material data

          bapi_marax,  " Information on update for CLIENTDATA

          bapi_marc,   " Plant-specific material data

          bapi_marcx,  " Information on update for PLANTDATA

          bapi_mard,   " Storage-location-specific material data

          bapi_mardx,  " Information on update for STORAGELOCATIONDATA

          bapi_mbew,   " Valuation data

          bapi_mbewx,  " Information on update for VALUATIONDATA

          bapi_makt,   " Material descriptions

          bapi_marm,   " Units of measure

          bapi_marmx,  " Information on update for UNITSOFMEASURE

          bapi_mltx,   " Long texts

          bapiret2.    " Return parameters

TYPES : BEGIN OF ty_master,

        matnr(18),   " Material Number

        mbrsh(1),    " Industry Sector

        mtart(4),    " Material Type

        werks(4),    " Plant

        lgort(4),    " Storage Location

        maktx(40),   " Material Description

        meins(3),    " Base Unit of measure

        matkl(9),    " Material Group

        bismt(18),   " Old Material Number

        ekgrp(3),    " Purchasing Group

        bstme(3),    " Order unit

        webaz(3),    " GR Procesing Time

        tdline(132), " Purchase Order Text

        disgr(4),    " MRP Group

        maabc(1),    " ABC Indicator

        dismm(2),    " MRP Type

        dispo(3),    " MRP Controller

        lgfsb(4),    " Storage Loc for EP

        plifz(3),    " Planned Delivery Time

        perkz(1),    " Period Indicator

        mtvfp(2),    " Availability Check

        lgpbe(10),   " Storage Bin

        bwkey(4),    " Valuation Area

        bklas(4),    " Valuation Class

        vprsv(1),    " Price Control

        verpr(11),   " Moving Price

        peinh(5),    " Price Unit

        meinh(3),    " alternate_unit 1

        umren(5),    " denominator 1

        umrez(5),    " numerator 1

        alt_un(3),   " alternate_unit 2

        denom(5),    " denominator 2

        numer(5),    " numerator 2

        minbe(13),   " reorder point

        disls(2),    " lot size

        mabst(13),   " Maximum Stock level

        END OF ty_master.

*DATA: BEGIN OF  it_matmaster OCCURS 0.

*        INCLUDE STRUCTURE ty_master.

*DATA: END OF it_matmaster.

DATA : it_matmaster TYPE STANDARD TABLE OF ty_master,

        wa_matmaster TYPE ty_master.

DATA: BEGIN OF it_return OCCURS 0.

         INCLUDE STRUCTURE bapiret2.

DATA: END OF it_return.

DATA: BEGIN OF it_marm OCCURS 0.

         INCLUDE STRUCTURE bapi_marm.

DATA: END OF it_marm.

DATA: BEGIN OF it_marmx OCCURS 0.

         INCLUDE STRUCTURE bapi_marmx.

DATA: END OF it_marmx.

DATA: BEGIN OF it_mltx OCCURS 0.

         INCLUDE STRUCTURE bapi_mltx.

DATA: END OF it_mltx.

DATA: BEGIN OF it_materialdesc OCCURS 0.

         INCLUDE STRUCTURE bapi_makt .

DATA: END OF it_materialdesc.

******Selection Screen

SELECTION-SCREEN BEGIN OF BLOCK rad1 WITH FRAME TITLE text-002.

PARAMETERS: pa_fname LIKE rlgrap-filename.

SELECTION-SCREEN END OF BLOCK rad1.

**********Added For Authority check for the user

AUTHORITY-CHECK OBJECT 'S_PROGRAM'

                    ID  'P_GROUP'  FIELD 'ZAML'

                    ID  'P_ACTION' FIELD 'SUBMIT'.

IF sy-subrc NE '0'.

   MESSAGE ID 'ZHR' TYPE 'E' NUMBER 004 WITH 'You are not Authorized'.

ENDIF.

******At Selection screen

AT SELECTION-SCREEN ON VALUE-REQUEST FOR pa_fname.

****** To get the File name

   CALL FUNCTION 'F4_FILENAME'

     EXPORTING

       field_name = 'PA_FNAME'

     IMPORTING

       file_name  = pa_fname.

******Start of Selection

START-OF-SELECTION.

****** Convert the excel file to sap format

   CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

     EXPORTING

       i_line_header        = 'X'

       i_tab_raw_data       = wa_tab_raw_data

       i_filename           = pa_fname

     TABLES

       i_tab_converted_data = it_matmaster[]

     EXCEPTIONS

       conversion_failed    = 1

       OTHERS               = 2.

   IF sy-subrc <> 0.

     MESSAGE i016(pg) WITH 'Invalid file. Please check again'.

     STOP.

   ENDIF.

IF it_matmaster[] IS  NOT INITIAL.

LOOP AT it_matmaster INTO wa_matmaster.

*      CLEAR bapimathead.

*      BREAK-POINT.

       CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

         EXPORTING

           input  = wa_matmaster-matnr

         IMPORTING

           output = wa_matmaster-matnr.

*******Header Details

       bapimathead-material   = wa_matmaster-matnr.

       bapimathead-ind_sector = wa_matmaster-mbrsh.

       bapimathead-matl_type  = wa_matmaster-mtart.

       bapimathead-basic_view = 'X'.

       bapimathead-mrp_view   = 'X'.

       bapimathead-storage_view  = 'X'.

       bapimathead-account_view  = 'X'.

       bapimathead-purchase_view = 'X'.

       CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'

         EXPORTING

           input    = wa_matmaster-meins

           language = sy-langu

         IMPORTING

           output   = wa_matmaster-meins.

****Mara Table Details

       bapi_mara-matl_group   =  wa_matmaster-matkl.

       bapi_mara-base_uom     =  wa_matmaster-meins.

       bapi_mara-base_uom_iso =  wa_matmaster-meins.

       bapi_mara-old_mat_no   =  wa_matmaster-bismt.

       CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'

         EXPORTING

           input    = wa_matmaster-bstme

           language = sy-langu

         IMPORTING

           output   = wa_matmaster-bstme.

       bapi_mara-po_unit       = wa_matmaster-bstme.

       bapi_marax-matl_group   =  'X'.

       bapi_marax-base_uom     =  'X'.

       bapi_marax-base_uom_iso =  'X'.

       bapi_marax-old_mat_no   =  'X'.

       bapi_marax-po_unit      = 'X'.

*****MARC Table Details

       bapi_marc-plant          = wa_matmaster-werks.

       bapi_marc-pur_group      = wa_matmaster-ekgrp.

       bapi_marc-mrp_type       = wa_matmaster-dismm.

       bapi_marc-mrp_ctrler     = wa_matmaster-dispo.

       bapi_marc-abc_id         = wa_matmaster-maabc.

       bapi_marc-plnd_delry     = wa_matmaster-plifz.

       bapi_marc-gr_pr_time     = wa_matmaster-webaz.

       bapi_marc-period_ind     = wa_matmaster-perkz.

       bapi_marc-mrp_group      = wa_matmaster-disgr.

       bapi_marc-sloc_exprc     = wa_matmaster-lgfsb.

       bapi_marc-availcheck     = wa_matmaster-mtvfp.

       bapi_marc-REORDER_PT     = wa_matmaster-minbe.

       bapi_marc-LOTSIZEKEY     = wa_matmaster-disls.

       bapi_marc-MAX_STOCK      = wa_matmaster-mabst.

       bapi_marcx-plant         = wa_matmaster-werks.

       bapi_marcx-pur_group     = 'X'.

       bapi_marcx-mrp_type      = 'X'.

       bapi_marcx-mrp_ctrler    = 'X'.

       bapi_marcx-abc_id        = 'X'.

       bapi_marcx-plnd_delry    = 'X'.

       bapi_marcx-gr_pr_time    = 'X'.

       bapi_marcx-period_ind    = 'X'.

       bapi_marcx-mrp_group     = 'X'.

       bapi_marcx-sloc_exprc    = 'X'.

       bapi_marcx-availcheck    = 'X'.

       bapi_marcx-REORDER_PT    = 'X'.

       bapi_marcx-LOTSIZEKEY    = 'X'.

       bapi_marcx-MAX_STOCK     = 'X'.

*****MARD Table Details

       bapi_mard-plant          = wa_matmaster-werks.

       bapi_mard-stge_loc       = wa_matmaster-lgort.

       bapi_mard-stge_bin       = wa_matmaster-lgpbe.

       bapi_mardx-plant         = wa_matmaster-werks.

       bapi_mardx-stge_loc      = wa_matmaster-lgort.

       bapi_mardx-stge_bin      = 'X'.

******MBEW Table Details

       bapi_mbew-val_area       = wa_matmaster-bwkey.

       bapi_mbew-val_class      = wa_matmaster-bklas.

       bapi_mbew-price_ctrl     = wa_matmaster-vprsv.

       bapi_mbew-moving_pr      = wa_matmaster-verpr.

       bapi_mbew-price_unit     = wa_matmaster-peinh.

       bapi_mbewx-val_area      = wa_matmaster-bwkey.

       bapi_mbewx-val_class     = 'X'.

       bapi_mbewx-price_ctrl    = 'X'.

       bapi_mbewx-moving_pr     = 'X'.

       bapi_mbewx-price_unit    = 'X'.

*****Material Description Details

       it_materialdesc-langu            = 'EN'.

       it_materialdesc-matl_desc        = wa_matmaster-maktx.

       APPEND it_materialdesc.

       CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'

         EXPORTING

           input    = wa_matmaster-meinh

           language = sy-langu

         IMPORTING

           output   = wa_matmaster-meinh.

*****Material Unit of Measure

       it_marm-alt_unit   = wa_matmaster-meinh.

       it_marm-numerator  = wa_matmaster-umrez.

       it_marm-denominatr = wa_matmaster-umren.

       APPEND it_marm.

       it_marmx-alt_unit   = wa_matmaster-meinh.

       it_marmx-numerator  = 'X'.

       it_marmx-denominatr = 'X'.

       APPEND it_marmx.

*****Alternate unit of measure 2

       IF wa_matmaster-alt_un IS NOT INITIAL.

         it_marm-alt_unit   = wa_matmaster-alt_un. " alternate_unit 2

         it_marm-numerator  = wa_matmaster-denom.  " denominator 2

         it_marm-denominatr = wa_matmaster-numer.  " numerator 2

         APPEND it_marm.

         it_marmx-alt_unit   = wa_matmaster-alt_un.

         it_marmx-numerator  = 'X'.

         it_marmx-denominatr = 'X'.

         APPEND it_marmx.

       ENDIF.

**** Material Long Text

       it_mltx-text_name = wa_matmaster-matnr.

       it_mltx-langu = 'EN'.

       it_mltx-applobject = 'MATERIAL'.

       it_mltx-text_id = 'BEST'.

       it_mltx-text_line = wa_matmaster-tdline.

       APPEND it_mltx.

       CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'

         EXPORTING

           headdata             = bapimathead

           clientdata           = bapi_mara

           clientdatax          = bapi_marax

           plantdata            = bapi_marc

           plantdatax           = bapi_marcx

           storagelocationdata  = bapi_mard

           storagelocationdatax = bapi_mardx

           valuationdata        = bapi_mbew

           valuationdatax       = bapi_mbewx

         IMPORTING

           return               = it_return

         TABLES

           materialdescription  = it_materialdesc

           unitsofmeasure       = it_marm

           unitsofmeasurex      = it_marmx

           materiallongtext     = it_mltx.

       IF it_return-type EQ 'S'.

         CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

       ENDIF.

       lv_sno = lv_sno + 1.

       wmsstab-sno = lv_sno.

       wmsstab-msgtyp = it_return-type.

       wmsstab-plant = wa_matmaster-werks.

       wmsstab-mstring = it_return-message.

       APPEND wmsstab TO tmsstab.

       CLEAR : wmsstab,

               bapimathead,

               bapi_mara,

               bapi_marax,

               bapi_marc,

               bapi_marcx,

               bapi_mard,

               bapi_mardx,

               bapi_mbew,

               bapi_mbewx,

               it_materialdesc,

               it_marm,

               it_marmx,

               it_mltx,

               wa_matmaster.

     ENDLOOP.

     PERFORM print_msg.

ELSE.

     MESSAGE 'No data found' TYPE 'S' DISPLAY LIKE 'E'.

ENDIF.

Former Member

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question