Skip to Content

BAPI_MATERIAL_SAVEDATA Error M3 407

Hi,

When I'm updating a materialnumber with BAPI_MATERIAL_SAVEDATA, I sometimes get the error M3 407 Enter a valuation class (Geben Sie eine Bewertungsklasse ein) .

Although not checked all cases yet, it seems to be to happen when the accounting info is failing. I don't have checked anything for the valuationdatax-table, so I don't see why the programm is giving an error on this.

The field I want to update is updated, but of course it would be better if no error was given. Is it possible that the BAPI doesn't check this field when the Accounting-data isn't available yet ? Or is the reason not the fact that the Account-part is failing, but something else ?

The field I do want to update is plantdata-pur_status.

TIA,

Alain

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Posted on Jul 22, 2008 at 03:05 PM

    when you update the status have you also passed the plant to the bapi ? otherwise it wants to create a record I guess for a new plant

    *PLANT GEGEVENS
      h_bapi_marc-plant = p_plant.
      h_bapi_marc-availcheck = 'KP'.
      h_bapi_marc-neg_stocks = 'X'.
      h_bapi_marc-profit_ctr = p_profit.
    
    
      h_bapi_marcx-plant = p_plant.
      h_bapi_marcx-availcheck = 'X'.
      h_bapi_marcx-neg_stocks = 'X'.
      h_bapi_marcx-profit_ctr = 'X'.
    
    

    plant is mandatory to pass also, if that doesn't have the correct value I guess the bapi also want to do some other things as well.

    also notice that in the marcx the plant is passed instead of X !

    kind regards

    arthur de smidt

    Add a comment
    10|10000 characters needed characters exceeded

    • I believe for the material you also have to fill

        h_headdata-material = zmm00004-matnr.
        h_headdata-ind_sector = 'O'.
        h_headdata-matl_type = c_matl_type.
      

      if you go to mm02 to the material is val_class mandatory ??

      otherwise just try to pass the info already from the material again to the bapi.

        h_bapi_mbew-val_area = zmm00004-werks.
        h_bapi_mbew-val_class = '5322'.
        h_bapi_mbew-price_ctrl = 'V'.
        h_bapi_mbew-price_unit = '10000'.
        h_bapi_mbew-plndprice1 = '0.01'.
        h_bapi_mbew-plndprdate1 = '20060101'.
      
        h_bapi_mbewx-val_area = zmm00004-werks.
        h_bapi_mbewx-val_class = 'X'.
        h_bapi_mbewx-price_ctrl = 'X'.
        h_bapi_mbewx-price_unit = 'X'.
        h_bapi_mbewx-plndprice1 = 'X'.
        h_bapi_mbewx-plndprdate1 = 'X'.
      
      

      it's quite difficult bapi to get into control but once it's working it makes up for all the troubles it has caused figuring out 😉

      kind regards

      arthur

  • author's profile photo Former Member
    Former Member
    Posted on Jul 23, 2008 at 06:23 AM

    See if the following code helps.

    Its working fine and all the views are getting created.

    =============

    &----


    *& Report ZMM_MATERIAL_MASTER_UPLOAD

    *&

    &----


    *&

    *&

    &----


    ----


    • Program Name : ZMM_MATERIAL_MASTER_UPLOAD

    • Type / Module : Report/MM

    • Created by : Sachin Dabhade

    • Created on : 19.10.2007

    • Requestor : Audhithan M

    • CRF No. : NA

    ----


    • This program is used to fetch the newly arrived material

    *from table : ZMM_RTM_FIELDS and to create the material master.

    *It is creating all the accounting, costing, sales and purchasing views along

    *with the basic views

    • The RTM file is loaded into the Ztable using a saperate program : ZMM_MATERIAL_MASTER_ZTAB

    • We are using Ztables like :

    *Table : ZMM_RTM_FIELDS to hold all the RTM fields,

    *Table : ZMM_MATERIAL to store all the default values for all the views.

    *Table : ZMM_MATERIAL_SAL to store Plant and associated sales areas. Could be Maintained via SM30

    *Table : ZMM_MAT_TYPES to store the mapping of RTM Material types. Could be Maintained via SM30

    *corresponding SAP Material Type.

    *

    *

    *

    ----


    • Modification Log:

    ----


    *CRF No.

    *Date ABAPer Functional Consultant Description

    *

    ----


    REPORT ZMM_MATERIAL_MASTER_UPLOAD.

    DATA: ITAB TYPE ZMM_RTM_FIELDS OCCURS 100 WITH HEADER LINE.

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

    DATA: Z_RTM TYPE ZMM_RTM_FIELDS OCCURS 100 WITH HEADER LINE.

    DATA: Z_RTM1 TYPE ZMM_RTM_FIELDS OCCURS 100 WITH HEADER LINE.

    DATA : ITAB_MTYPE TYPE ZMM_MAT_TYPES OCCURS 0 WITH HEADER LINE.

    DATA : Z_MTART LIKE ZMM_RTM_FIELDS-CODSTRUTDIS.

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

    DATA : ITAB_VIEW LIKE ZMM_MATERIAL OCCURS 0 WITH HEADER LINE.

    DATA : ITAB_SALES_AREA LIKE ZMM_MATERIAL_SAL OCCURS 0 WITH HEADER LINE.

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

    • Declaration for BAPI

    DATA : MATHEAD LIKE BAPIMATHEAD,

    CLIENTDATA LIKE BAPI_MARA,

    CLIENTDATAX LIKE BAPI_MARAX,

    PLANTDATA LIKE BAPI_MARC,

    PLANTDATAX LIKE BAPI_MARCX,

    FORECASTPARAMETERS LIKE BAPI_MPOP,

    FORECASTPARAMETERSX LIKE BAPI_MPOPX,

    PLANNINGDATA LIKE BAPI_MPGD,

    PLANNINGDATAX LIKE BAPI_MPGDX,

    STORAGELOCATIONDATA LIKE BAPI_MARD,

    STORAGELOCATIONDATAX LIKE BAPI_MARDX,

    VALUATIONDATA LIKE BAPI_MBEW,

    VALUATIONDATAX LIKE BAPI_MBEWX,

    WAREHOUSENUMBERDATA LIKE BAPI_MLGN,

    WAREHOUSENUMBERDATAX LIKE BAPI_MLGNX,

    SALESDATA LIKE BAPI_MVKE,

    SALESDATAX LIKE BAPI_MVKEX,

    STORAGETYPEDATA LIKE BAPI_MLGT,

    STORAGETYPEDATAX LIKE BAPI_MLGTX,

    RETURN LIKE BAPIRET2,

    RET1 LIKE BAPIRET2,

    MATERIALDESCRIPTION LIKE BAPI_MAKT OCCURS 0 WITH HEADER LINE,

    UNITSOFMEASURE LIKE BAPI_MARM OCCURS 0 WITH HEADER LINE,

    UNITSOFMEASUREX LIKE BAPI_MARMX OCCURS 0 WITH HEADER LINE,

    INTERNATIONALARTNOS LIKE BAPI_MEAN OCCURS 0 WITH HEADER LINE,

    MATERIALLONGTEXT LIKE BAPI_MLTX OCCURS 0 WITH HEADER LINE,

    TAXCLASSIFICATIONS LIKE BAPI_MLAN OCCURS 0 WITH HEADER LINE,

    PRTDATA LIKE BAPI_MFHM OCCURS 0 WITH HEADER LINE,

    PRTDATAX LIKE BAPI_MFHMX OCCURS 0 WITH HEADER LINE,

    RETMES LIKE BAPI_MATRETURN2 OCCURS 0 WITH HEADER LINE.

    DATA : L_MATNR LIKE MARA-MATNR.

    DATA : BEGIN OF L_ITAB,

    L_MATNR TYPE MARA-MATNR,

    L_MATKL TYPE MARA-MATKL,

    L_SPART TYPE MARA-SPART,

    END OF L_ITAB.

    DATA : BEGIN OF ITAB_STATUS OCCURS 0,

    MANDT TYPE ZMM_ERROR_068-MANDT,

    MATERIAL TYPE ZMM_ERROR_068-MATERIAL,

    FILE_NAME TYPE ZMM_ERROR_068-FILE_NAME,

    FILE_TIME TYPE ZMM_ERROR_068-FILE_TIME,

    FILE_DATE TYPE ZMM_ERROR_068-FILE_DATE,

    ERROR_TYPE TYPE ZMM_ERROR_068-ERROR_TYPE,

    ERROR_MSG TYPE ZMM_ERROR_068-ERROR_MSG,

    END OF ITAB_STATUS.

    DATA : I_TEXT TYPE STRING.

    DATA : BEGIN OF ITAB_EMAIL OCCURS 0,

    MATERIAL TYPE ZMM_ERROR_081-MATERIAL,

    ERROR_MSG TYPE ZMM_ERROR_081-ERROR_MSG,

    END OF ITAB_EMAIL.

    *PARAMETER: p_file LIKE rlgrap-filename DEFAULT

    • 'c:\data\test_mm.txt'.

    *

    *SELECTION-SCREEN SKIP.

    *SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME TITLE text-001.

    *

    *SELECTION-SCREEN END OF BLOCK blk.

    *

    *AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

    • PERFORM getfile CHANGING p_file.

    INITIALIZATION.

    PERFORM INIT_BAPI_VAR.

    START-OF-SELECTION.

    • PERFORM readfile.

    *

    • IF itab[] IS INITIAL.

    • WRITE : 'No Data in Uploaded File...Plz Chk'(e03)

    • COLOR 6 INTENSIFIED.

    • ENDIF.

    PERFORM PREPARE_ZTABLE.

    IF SY-SUBRC = 0.

    • PERFORM GET_MATERIAL_TYPES.

    • PERFORM GET_VIEW_DETAILS.

    • PERFORM GET_SALES_AREA_DETAILS.

    LOOP AT Z_RTM.

    PERFORM SPLIT_REC.

    • PERFORM EXEC_BAPI.

    ENDLOOP .

    PERFORM INSERT_ZTABLE.

    IF NOT ITAB_STATUS[] IS INITIAL.

    • PERFORM SEND_MESSAGE.

    PERFORM UPDATE_ERROR_LOG.

    ENDIF.

    IF NOT ITAB_EMAIL[] IS INITIAL.

    PERFORM SEND_MESSAGE.

    ENDIF.

    ELSE.

    WRITE: 'No New Material identified'.

    ENDIF.

    &----


    *& Form split_rec

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM SPLIT_REC.

    • FOR TESTING IN 150 ONLY.

    *Z_RTM-zWERKS = '1000'.

    • LATER TO BE REMOVED.

    PERFORM INIT_BAPI_VAR.

    CLEAR Z_MTART.

    IF Z_RTM-RECORDCODE = 'DIS1'.

    • HEADER DATA

    MATHEAD-MATERIAL = Z_RTM-MATERIAL.

    MATHEAD-IND_SECTOR = 'M'.

    • MATHEAD-MATL_TYPE = ITAB_MTYPE-SAP_TYPE.

    IF Z_RTM-MATERIAL+11(1) = 'E'.

    • READ TABLE ITAB_MTYPE WITH KEY RTM_TYPE = Z_RTM-CODSTRUTDIS.

    • IF SY-SUBRC = 0.

    • MATHEAD-MATL_TYPE = ITAB_MTYPE-SAP_TYPE.

    • Z_MTART = ITAB_MTYPE-SAP_TYPE.

    *

    • ELSE.

    • READ TABLE ITAB_MTYPE WITH KEY RTM_TYPE = Z_RTM-CODSTRUTDIS.

    • IF SY-SUBRC = 0.

    • IF Z_RTM-CODSTRUTDIS(1) = '3' OR Z_RTM-CODSTRUTDIS(1) = '1'.

    • MATHEAD-MATL_TYPE = 'HALB'.

    • Z_MTART = 'HALB'.

    • ELSE.

    • MATHEAD-MATL_TYPE = 'ROH'.

    • Z_MTART = 'ROH'.

    • ENDIF.

    • ELSE.

    MATHEAD-MATL_TYPE = 'ROH'.

    Z_MTART = 'ROH'.

    • ENDIF.

    ENDIF.

    IF Z_RTM-MATERIAL+11(1) = 'I'.

    MATHEAD-MATL_TYPE = 'HALB'.

    Z_MTART = 'HALB'.

    ENDIF.

    • READ TABLE ITAB_MTYPE WITH KEY RTM_TYPE = Z_RTM-CODSTRUTDIS.

    • IF SY-SUBRC = 0.

    • MATHEAD-MATL_TYPE = ITAB_MTYPE-SAP_TYPE.

    • ENDIF.

    MATHEAD-BASIC_VIEW = 'X'.

    • MATHEAD-SALES_VIEW = 'X'.

    • MATHEAD-PURCHASE_VIEW = 'X'.

    • MATHEAD-MRP_VIEW = 'X'.

    • MATHEAD-ACCOUNT_VIEW = 'X'.

    • MATHEAD-COST_VIEW = 'X'.

    MATHEAD-STORAGE_VIEW = 'X'.

    • MATERIAL DESCRIPTION TABLE

    MATERIALDESCRIPTION-MATL_DESC = Z_RTM-DENDIS.

    MATERIALDESCRIPTION-LANGU = 'E'.

    MATERIALDESCRIPTION-LANGU_ISO = 'EN'.

    APPEND MATERIALDESCRIPTION.

    TAXCLASSIFICATIONS-DEPCOUNTRY = 'IN'.

    TAXCLASSIFICATIONS-TAX_TYPE_1 = 'JTX1'.

    TAXCLASSIFICATIONS-TAXCLASS_1 = '1'.

    APPEND TAXCLASSIFICATIONS.

    CLEAR TAXCLASSIFICATIONS.

    TAXCLASSIFICATIONS-DEPCOUNTRY = 'IN'.

    TAXCLASSIFICATIONS-TAX_TYPE_1 = 'JTX2'.

    TAXCLASSIFICATIONS-TAXCLASS_1 = '1'.

    APPEND TAXCLASSIFICATIONS.

    CLEAR TAXCLASSIFICATIONS.

    TAXCLASSIFICATIONS-DEPCOUNTRY = 'IN'.

    TAXCLASSIFICATIONS-TAX_TYPE_1 = 'JTX3'.

    TAXCLASSIFICATIONS-TAXCLASS_1 = '1'.

    APPEND TAXCLASSIFICATIONS.

    CLEAR TAXCLASSIFICATIONS.

    TAXCLASSIFICATIONS-DEPCOUNTRY = 'IN'.

    TAXCLASSIFICATIONS-TAX_TYPE_1 = 'JTX4'.

    TAXCLASSIFICATIONS-TAXCLASS_1 = '1'.

    APPEND TAXCLASSIFICATIONS.

    CLEAR TAXCLASSIFICATIONS.

    • CLIENT DATA

    L_MATNR = Z_RTM-MATERIAL.

    TRANSLATE L_MATNR TO UPPER CASE.

    SELECT SINGLE MATNR MATKL SPART FROM MARA INTO L_ITAB WHERE MATNR = L_MATNR.

    IF SY-SUBRC = 0.

    CLIENTDATA-MATL_GROUP = L_ITAB-L_MATKL.

    CLIENTDATAX-MATL_GROUP = 'X'.

    IF L_ITAB-L_SPART IS INITIAL.

    IF Z_RTM-ZWERKS = '183'.

    CLIENTDATA-DIVISION = '10'.

    CLIENTDATAX-DIVISION = 'X'.

    ENDIF.

    IF Z_RTM-ZWERKS = '184'.

    CLIENTDATA-DIVISION = '20'.

    CLIENTDATAX-DIVISION = 'X'.

    ENDIF.

    ENDIF.

    ELSE.

    CLIENTDATA-MATL_GROUP = '01'.

    CLIENTDATAX-MATL_GROUP = 'X'.

    IF Z_RTM-ZWERKS = '183'.

    CLIENTDATA-DIVISION = '10'.

    CLIENTDATAX-DIVISION = 'X'.

    ENDIF.

    IF Z_RTM-ZWERKS = '184'.

    CLIENTDATA-DIVISION = '20'.

    CLIENTDATAX-DIVISION = 'X'.

    ENDIF.

    ENDIF.

    IF Z_RTM-UNITMIS = 'N' OR Z_RTM-UNITMIS = 'NOS'.

    CLIENTDATA-BASE_UOM = 'EA'.

    CLIENTDATA-BASE_UOM_ISO = 'EA'.

    CLIENTDATAX-BASE_UOM = 'X'.

    CLIENTDATAX-BASE_UOM_ISO = 'X'.

    • CLIENTDATA-MATL_GROUP = '01'.

    • CLIENTDATAX-MATL_GROUP = 'X'.

    CLIENTDATA-UNIT_OF_WT = Z_RTM-UNIMISMAT. " UNIT OF WEIGHT

    IF Z_RTM-UNIMISMAT IS INITIAL.

    CLIENTDATA-UNIT_OF_WT = 'KG'.

    ENDIF.

    CLIENTDATAX-UNIT_OF_WT = 'X'.

    CLIENTDATA-NET_WEIGHT = Z_RTM-VALOREPESO / 100000. " WEIGHT

    CLIENTDATAX-NET_WEIGHT = 'X'.

    ELSE.

    CLIENTDATA-BASE_UOM = Z_RTM-UNITMIS.

    CLIENTDATA-BASE_UOM_ISO = Z_RTM-UNITMIS.

    CLIENTDATAX-BASE_UOM = 'X'.

    CLIENTDATAX-BASE_UOM_ISO = 'X'.

    • CLIENTDATA-MATL_GROUP = '01'.

    • CLIENTDATAX-MATL_GROUP = 'X'.

    CLIENTDATA-UNIT_OF_WT = Z_RTM-UNIMISMAT. " UNIT OF WEIGHT

    IF Z_RTM-UNIMISMAT IS INITIAL.

    CLIENTDATA-UNIT_OF_WT = 'KG'.

    ENDIF.

    CLIENTDATAX-UNIT_OF_WT = 'X'.

    CLIENTDATA-NET_WEIGHT = Z_RTM-VALOREPESO. " WEIGHT

    CLIENTDATAX-NET_WEIGHT = 'X'.

    ENDIF.

    PLANTDATA-PLANT = Z_RTM-ZWERKS.

    PLANTDATAX-PLANT = Z_RTM-ZWERKS.

    IF Z_RTM-ZWERKS = '183'.

    PLANTDATA-PROFIT_CTR = '0000001100'.

    ENDIF.

    IF Z_RTM-ZWERKS = '184'.

    PLANTDATA-PROFIT_CTR = '0000002300'.

    ENDIF.

    PLANTDATAX-PROFIT_CTR = 'X'.

    • MRP1 related fields are derived here from ZTable

  • READ TABLE ITAB_VIEW WITH KEY MTART = Z_MTART ZVIEW = 'M1'.

  • READ TABLE ITAB_VIEW WITH KEY MTART = Z_MTART ZVIEW = 'M1' WERKS = Z_RTM-ZWERKS.

  • *

    • IF SY-SUBRC = 0.

    • PLANTDATA-PLANT = ITAB_VIEW-WERKS.

    • PLANTDATAX-PLANT = ITAB_VIEW-WERKS.

    • PLANTDATA-PROFIT_CTR = ITAB_VIEW-PRCTR.

    • PLANTDATAX-PROFIT_CTR = 'X'.

  • PLANTDATA-MRP_GROUP = ITAB_VIEW-DISGR.

  • PLANTDATAX-MRP_GROUP = 'X'.

  • PLANTDATA-MRP_TYPE = ITAB_VIEW-DISMM.

  • PLANTDATAX-MRP_TYPE = 'X'.

  • PLANTDATA-MRP_CTRLER = ITAB_VIEW-DISPO. " '001'.

  • PLANTDATAX-MRP_CTRLER = 'X'.

  • PLANTDATA-LOTSIZEKEY = ITAB_VIEW-DISLS.

  • PLANTDATAX-LOTSIZEKEY = 'X'.

  • PLANTDATA-ABC_ID = ITAB_VIEW-MAABC.

  • PLANTDATAX-ABC_ID = 'X'.

  • ENDIF.

  • *

    • MPR2 related fields are derived here from ZTable

  • READ TABLE ITAB_VIEW WITH KEY MTART = Z_MTART ZVIEW = 'M2' .

  • READ TABLE ITAB_VIEW WITH KEY MTART = Z_MTART ZVIEW = 'M2' WERKS = Z_RTM-ZWERKS.

  • IF SY-SUBRC = 0.

  • PLANTDATA-PROC_TYPE = ITAB_VIEW-BESKZ.

  • PLANTDATAX-PROC_TYPE = 'X'.

  • PLANTDATA-SM_KEY = ITAB_VIEW-FHORI.

  • PLANTDATAX-SM_KEY = 'X'.

  • ENDIF.

  • *

    • MPR3 related fields are derived here from ZTable

  • READ TABLE ITAB_VIEW WITH KEY MTART = Z_MTART ZVIEW = 'M3' .

  • READ TABLE ITAB_VIEW WITH KEY MTART = Z_MTART ZVIEW = 'M3' WERKS = Z_RTM-ZWERKS.

  • IF SY-SUBRC = 0.

  • PLANTDATA-AVAILCHECK = ITAB_VIEW-MTVFP.

  • PLANTDATAX-AVAILCHECK = 'X'.

  • PLANTDATA-PLAN_STRGP = ITAB_VIEW-STRGR.

  • PLANTDATAX-PLAN_STRGP = 'X'.

  • PLANTDATA-PERIOD_IND = ITAB_VIEW-PERKZ.

  • PLANTDATAX-PERIOD_IND = 'X'.

  • PLANTDATA-AVAILCHECK = ITAB_VIEW-MTVFP.

  • PLANTDATAX-AVAILCHECK = 'X'.

  • *

    • PLANTDATA-CONSUMMODE = ITAB_VIEW-VRMOD.

    • PLANTDATAX-CONSUMMODE = 'X'.

    *

    • PLANTDATA-BWD_CONS = ITAB_VIEW-VINT1.

    • PLANTDATAX-BWD_CONS = 'X'.

    *

    • PLANTDATA-FWD_CONS = ITAB_VIEW-VINT2.

    • PLANTDATAX-FWD_CONS = 'X'.

    *

    • ENDIF.

    • MRP4 related fields are derived here from ZTable

    • PURCHASING related fields are derived here from ZTable

    • READ TABLE ITAB_VIEW WITH KEY MTART = Z_MTART ZVIEW = 'P'.

    READ TABLE ITAB_VIEW WITH KEY MTART = Z_MTART ZVIEW = 'P' WERKS = Z_RTM-ZWERKS.

    IF SY-SUBRC = 0.

    CLIENTDATA-PUR_VALKEY = ITAB_VIEW-EKWSL .

    CLIENTDATAX-PUR_VALKEY = 'X'.

    • PLANTDATA-PUR_GROUP = ITAB_VIEW-EKGRP. " '110'.

    • PLANTDATAX-PUR_GROUP = 'X'.

    • PLANTDATA-QUOTAUSAGE = ITAB_VIEW-USEQU.

    • PLANTDATA-SOURCELIST = ITAB_VIEW-KORDB.

    • PLANTDATAX-SOURCELIST = 'X'.

    *

    • PLANTDATA-GR_PR_TIME = ITAB_VIEW-WEBAZ.

    • PLANTDATAX-GR_PR_TIME = 'X'.

    STORAGELOCATIONDATA-PLANT = Z_RTM-ZWERKS.

    STORAGELOCATIONDATAX-PLANT = Z_RTM-ZWERKS.

    STORAGELOCATIONDATA-STGE_LOC = ITAB_VIEW-LGORT.

    STORAGELOCATIONDATAX-STGE_LOC = ITAB_VIEW-LGORT.

    ENDIF.

    • COST1 related fields are derived here from ZTable

  • READ TABLE ITAB_VIEW WITH KEY MTART = Z_MTART ZVIEW = 'C1' .

  • READ TABLE ITAB_VIEW WITH KEY MTART = Z_MTART ZVIEW = 'C1' WERKS = Z_RTM-ZWERKS.

    IF SY-SUBRC = 0.

    VALUATIONDATA-QTY_STRUCT = ITAB_VIEW-EKALR.

    VALUATIONDATAX-QTY_STRUCT = 'X'.

    VALUATIONDATA-ORIG_GROUP = ITAB_VIEW-HRKFT.

    VALUATIONDATAX-ORIG_GROUP = 'X'.

    VALUATIONDATA-ORIG_MAT = ITAB_VIEW-HKMAT.

    VALUATIONDATAX-ORIG_MAT = 'X'.

    ENDIF.

    • READ TABLE ITAB_VIEW WITH KEY MTART = Z_MTART ZVIEW = 'A1' .

    READ TABLE ITAB_VIEW WITH KEY MTART = Z_MTART ZVIEW = 'A1' WERKS = Z_RTM-ZWERKS.

    IF SY-SUBRC = 0.

    VALUATIONDATA-VAL_CLASS = ITAB_VIEW-BKLAS.

    VALUATIONDATAX-VAL_CLASS = 'X'.

    VALUATIONDATA-STD_PRICE = ITAB_VIEW-STPRS.

    VALUATIONDATAX-STD_PRICE = 'X'.

    ENDIF.

    • COST2 related fields are derived here from ZTable

  • READ TABLE ITAB_VIEW WITH KEY MTART = Z_MTART ZVIEW = 'C2' .

  • READ TABLE ITAB_VIEW WITH KEY MTART = Z_MTART ZVIEW = 'C2' WERKS = Z_RTM-ZWERKS.

    IF SY-SUBRC = 0.

    VALUATIONDATA-PLNDPRICE1 = ITAB_VIEW-ZPLP1.

    VALUATIONDATAX-PLNDPRICE1 = 'X'.

    VALUATIONDATA-PLNDPRDATE1 = SY-DATUM.

    VALUATIONDATAX-PLNDPRDATE1 = 'X'.

    VALUATIONDATA-PRICE_CTRL = ITAB_VIEW-VPRSV.

    VALUATIONDATAX-PRICE_CTRL = 'X'.

    VALUATIONDATA-PRICE_UNIT = ITAB_VIEW-PEINH.

    VALUATIONDATAX-PRICE_UNIT = 'X'.

    ENDIF.

    • SALES/PLANT related fields are derived here from ZTable

  • READ TABLE ITAB_VIEW WITH KEY MTART = Z_MTART ZVIEW = 'SP' .

  • READ TABLE ITAB_VIEW WITH KEY MTART = Z_MTART ZVIEW = 'SP' WERKS = Z_RTM-ZWERKS.

    IF SY-SUBRC = 0.

    PLANTDATA-LOADINGGRP = ITAB_VIEW-LADGR.

    PLANTDATAX-LOADINGGRP = 'X'.

    CLIENTDATA-TRANS_GRP = ITAB_VIEW-TRAGR.

    CLIENTDATAX-TRANS_GRP = 'X'.

    ENDIF.

    • SALES 2 related fields are derived here from ZTable

  • READ TABLE ITAB_VIEW WITH KEY MTART = Z_MTART ZVIEW = 'S2' .

  • READ TABLE ITAB_VIEW WITH KEY MTART = Z_MTART ZVIEW = 'S2' WERKS = Z_RTM-ZWERKS.

    IF SY-SUBRC = 0.

    SALESDATA-MATL_STATS = ITAB_VIEW-VERSG.

    SALESDATAX-MATL_STATS = 'X'.

    SALESDATA-ITEM_CAT = ITAB_VIEW-MTPOS.

    SALESDATAX-ITEM_CAT = 'X'.

    CLIENTDATA-ITEM_CAT = ITAB_VIEW-MTPOS_MARA.

    CLIENTDATAX-ITEM_CAT = 'X'.

    ENDIF.

    • SALES 1 related fields are derived here from ZTable

  • READ TABLE ITAB_VIEW WITH KEY MTART = Z_MTART ZVIEW = 'S1' WERKS = Z_RTM-DESTINDIS.

    • LOOP AT ITAB_SALES_AREA WHERE WERKS = ITAB_VIEW-WERKS AND ZVIEW = 'S1'.

    LOOP AT ITAB_SALES_AREA WHERE WERKS = Z_RTM-ZWERKS. " Z_RTM-DESTINDIS AND ZVIEW = 'S1'.

    • IMPORTANT : THE VALUATION AREA IS MANDATORY AND IS MAINTAINED IN TABLE : ZMM_MATERIAL_SAL ***************

    VALUATIONDATA-VAL_AREA = ITAB_SALES_AREA-VAL_AREA.

    VALUATIONDATAX-VAL_AREA = ITAB_SALES_AREA-VAL_AREA.

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

    SALESDATA-SALES_ORG = ITAB_SALES_AREA-VKORG.

    SALESDATAX-SALES_ORG = ITAB_SALES_AREA-VKORG.

    SALESDATA-DISTR_CHAN = ITAB_SALES_AREA-VTWEG.

    SALESDATAX-DISTR_CHAN = ITAB_SALES_AREA-VTWEG.

    SALESDATA-DELYG_PLNT = ITAB_SALES_AREA-DWERK.

    CLIENTDATA-DIVISION = ITAB_SALES_AREA-SPART.

    CLIENTDATAX-DIVISION = 'X'.

    SALESDATAX-DELYG_PLNT = 'X'.

    • PERFORM EXEC_BAPI.

    CLEAR ITAB_SALES_AREA.

    ENDLOOP.

    PERFORM EXEC_BAPI.

    ENDIF.

    ENDFORM. " split_rec

    &----


    *& Form init_bapi_var

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM INIT_BAPI_VAR.

    CLEAR : MATHEAD, CLIENTDATA, CLIENTDATAX, PLANTDATA, PLANTDATAX,

    FORECASTPARAMETERS,FORECASTPARAMETERSX,PLANNINGDATA,

    PLANNINGDATAX,STORAGELOCATIONDATA,STORAGELOCATIONDATAX,

    VALUATIONDATA,VALUATIONDATAX,WAREHOUSENUMBERDATA,

    WAREHOUSENUMBERDATAX,SALESDATA,SALESDATAX,

    STORAGETYPEDATA,STORAGETYPEDATAX,MATERIALDESCRIPTION,

    UNITSOFMEASURE,UNITSOFMEASUREX,INTERNATIONALARTNOS,

    MATERIALLONGTEXT,TAXCLASSIFICATIONS,PRTDATA,PRTDATAX, RETURN,

    RETMES.

    REFRESH: MATERIALDESCRIPTION, UNITSOFMEASURE, UNITSOFMEASUREX,

    INTERNATIONALARTNOS, MATERIALLONGTEXT, TAXCLASSIFICATIONS,

    PRTDATA, PRTDATAX, RETMES.

    ENDFORM. " init_bapi_var

    &----


    *& Form exec_bapi

    &----


    • Bapi to create the material master

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM EXEC_BAPI.

    CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'

    EXPORTING

    HEADDATA = MATHEAD

    CLIENTDATA = CLIENTDATA

    CLIENTDATAX = CLIENTDATAX

    PLANTDATA = PLANTDATA

    PLANTDATAX = PLANTDATAX

    • forecastparameters = forecastparameters

    • forecastparametersx = forecastparametersx

    • PLANNINGDATA = PLANNINGDATA

    • PLANNINGDATAX = PLANNINGDATAX

    • STORAGELOCATIONDATA = STORAGELOCATIONDATA

    • STORAGELOCATIONDATAX = STORAGELOCATIONDATAX

    • VALUATIONDATA = VALUATIONDATA

    • VALUATIONDATAX = VALUATIONDATAX

    • warehousenumberdata = warehousenumberdata

    • warehousenumberdatax = warehousenumberdatax

    • SALESDATA = SALESDATA

    • SALESDATAX = SALESDATAX

    • storagetypedata = storagetypedata

    • storagetypedatax = storagetypedatax

    • FLAG_ONLINE = ' '

    IMPORTING

    RETURN = RETURN

    TABLES

    MATERIALDESCRIPTION = MATERIALDESCRIPTION

    • unitsofmeasure = unitsofmeasure

    • unitsofmeasurex = unitsofmeasurex

    • internationalartnos = internationalartnos

    • materiallongtext = materiallongtext

    • TAXCLASSIFICATIONS = TAXCLASSIFICATIONS

    • RETURNMESSAGES = retmes

    • prtdata = prtdata

    • prtdatax = prtdatax

    • EXTENSIONIN =

    • EXTENSIONINX =

    .

    CONCATENATE RETURN-MESSAGE MATHEAD-MATERIAL INTO I_TEXT SEPARATED BY SPACE.

    CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'

    EXPORTING

    PERCENTAGE = 100

    TEXT = I_TEXT.

    CLEAR : RET1.

    IF RETURN-TYPE = 'S'.

    • PERFORM INSERT_ZTABLE.

    • read table Z_RTM1 with key MATERIAL = MATHEAD-MATERIAL.

    Z_RTM1 = Z_RTM.

    Z_RTM1-ZNEW = ' '. " The flag is deselected after being used.

    APPEND Z_RTM1.

    • MODIFY Z_RTM1 transporting znew

    .

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

    EXPORTING

    WAIT = 'X'

    IMPORTING

    RETURN = RET1.

    IF RET1 IS INITIAL.

    FORMAT COLOR COL_POSITIVE INVERSE ON INTENSIFIED ON .

    WRITE:/005 MATHEAD-MATERIAL, RETURN-MESSAGE+(80).

    ITAB_EMAIL-MATERIAL = MATHEAD-MATERIAL.

    ITAB_EMAIL-ERROR_MSG = RETURN-MESSAGE+(80).

    APPEND ITAB_EMAIL.

    CLEAR ITAB_EMAIL.

    ELSE.

    FORMAT COLOR COL_GROUP INVERSE ON INTENSIFIED ON .

    WRITE:/005 MATHEAD-MATERIAL, 'Error while Commiting...'.

    ENDIF.

    ELSE.

    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'

    IMPORTING

    RETURN = RET1.

    FORMAT COLOR COL_NEGATIVE INVERSE ON INTENSIFIED ON.

    WRITE:/005 MATHEAD-MATERIAL, RETURN-MESSAGE+(80).

    • i_data_err = itab.

    • append i_data_err.

    IF RETURN-TYPE = 'E'.

    READ TABLE Z_RTM WITH KEY MATERIAL = MATHEAD-MATERIAL.

    ITAB_STATUS-MANDT = SY-MANDT.

    ITAB_STATUS-MATERIAL = MATHEAD-MATERIAL.

    ITAB_STATUS-FILE_NAME = Z_RTM-FILE_NAME.

    ITAB_STATUS-FILE_TIME = Z_RTM-FILE_TIME.

    ITAB_STATUS-FILE_DATE = Z_RTM-FILE_DATE.

    ITAB_STATUS-ERROR_TYPE = RETURN-TYPE.

    ITAB_STATUS-ERROR_MSG = RETURN-MESSAGE .

    APPEND ITAB_STATUS.

    CLEAR ITAB_STATUS.

    ENDIF.

    ENDIF.

    ENDFORM. " exec_bapi

    &----


    *& Form prepare_ztable.

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM PREPARE_ZTABLE.

    DATA ZNEW LIKE ZMM_RTM_FIELDS-ZNEW.

    SELECT * FROM ZMM_RTM_FIELDS INTO TABLE Z_RTM WHERE ZNEW = 'X' . " New material with flag X are selected.

    IF SY-SUBRC = 0.

    • Z_RTM1[] = Z_RTM[].

    • LOOP AT Z_RTM1.

    • Z_RTM1-ZNEW = ' '. " The flag is deselected after being used.

    • MODIFY Z_RTM1.

    • ENDLOOP.

    ENDIF.

    ENDFORM. " prepare_ztable.

    &----


    *& Form insert_ztable

    &----


    *

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM INSERT_ZTABLE .

    MODIFY ZMM_RTM_FIELDS FROM TABLE Z_RTM1. " If the Material is created, ZNEW flag is set to blank.

    IF SY-SUBRC = 0.

    COMMIT WORK.

    ENDIF.

    IF SY-SUBRC NE 0.

    WRITE ' Data not inserted in Z Table'.

    ENDIF.

    ENDFORM. " insert_ztable

    &----


    *& Form GET_VIEW_DETAILS

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM GET_VIEW_DETAILS .

    SELECT * FROM ZMM_MATERIAL INTO TABLE ITAB_VIEW . " Fetching the default values for all the views.

    ENDFORM. " GET_VIEW_DETAILS

    &----


    *& Form GET_MATERIAL_TYPES

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM GET_MATERIAL_TYPES .

    SELECT * FROM ZMM_MAT_TYPES INTO TABLE ITAB_MTYPE.

    ENDFORM. " GET_MATERIAL_TYPES

    &----


    *& Form GET_SALES_AREA_DETAILS

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM GET_SALES_AREA_DETAILS .

    SELECT * FROM ZMM_MATERIAL_SAL INTO TABLE ITAB_SALES_AREA.

    ENDFORM. " GET_SALES_AREA_DETAILS

    &----


    *& Form SEND_MESSAGE

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM SEND_MESSAGE .

    DATA: IT_MESSAGE TYPE STANDARD TABLE OF SOLISTI1 INITIAL SIZE 0 WITH HEADER LINE,

    GD_DOC_DATA LIKE SODOCCHGI1.

    DATA: IT_PACKING_LIST LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,

    IT_CONTENTS LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

    GD_SENT_ALL(1) TYPE C,

    IT_RECEIVERS LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE.

    APPEND 'The Following Materails Have Error Records' TO IT_MESSAGE.

    APPEND '==========================================' TO IT_MESSAGE.

    LOOP AT ITAB_EMAIL.

    CONCATENATE ITAB_EMAIL-MATERIAL ' : ' ITAB_EMAIL-ERROR_MSG INTO IT_MESSAGE.

    APPEND IT_MESSAGE.

    ENDLOOP.

    • Fill the document data.

    GD_DOC_DATA-DOC_SIZE = 1.

    • Populate the subject/generic message attributes

    GD_DOC_DATA-OBJ_LANGU = SY-LANGU.

    GD_DOC_DATA-OBJ_NAME = 'SAPRPT'.

    GD_DOC_DATA-OBJ_DESCR = ' Material Master Creation Error Log'.

    GD_DOC_DATA-SENSITIVTY = 'F'.

    • Describe the body of the message

    CLEAR IT_PACKING_LIST.

    REFRESH IT_PACKING_LIST.

    IT_PACKING_LIST-TRANSF_BIN = SPACE.

    IT_PACKING_LIST-HEAD_START = 1.

    IT_PACKING_LIST-HEAD_NUM = 0.

    IT_PACKING_LIST-BODY_START = 1.

    DESCRIBE TABLE IT_MESSAGE LINES IT_PACKING_LIST-BODY_NUM.

    IT_PACKING_LIST-DOC_TYPE = 'RAW'.

    APPEND IT_PACKING_LIST.

    • Add the recipients email address

    CLEAR IT_RECEIVERS.

    REFRESH IT_RECEIVERS.

    IT_RECEIVERS-RECEIVER = " Email Address to be appended here.

    IT_RECEIVERS-REC_TYPE = 'U'.

    IT_RECEIVERS-COM_TYPE = 'INT'.

    IT_RECEIVERS-NOTIF_DEL = 'X'.

    IT_RECEIVERS-NOTIF_NDEL = 'X'.

    APPEND IT_RECEIVERS.

    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    EXPORTING

    DOCUMENT_DATA = GD_DOC_DATA

    PUT_IN_OUTBOX = 'X'

    IMPORTING

    SENT_TO_ALL = GD_SENT_ALL

    TABLES

    PACKING_LIST = IT_PACKING_LIST

    CONTENTS_TXT = IT_MESSAGE

    RECEIVERS = IT_RECEIVERS

    EXCEPTIONS

    TOO_MANY_RECEIVERS = 1

    DOCUMENT_NOT_SENT = 2

    DOCUMENT_TYPE_NOT_EXIST = 3

    OPERATION_NO_AUTHORIZATION = 4

    PARAMETER_ERROR = 5

    X_ERROR = 6

    ENQUEUE_ERROR = 7

    OTHERS = 8.

    ENDFORM. " SEND_MESSAGE

    &----


    *& Form UPDATE_ERROR_LOG

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM UPDATE_ERROR_LOG .

    MODIFY ZMM_ERROR_068 FROM TABLE ITAB_STATUS.

    IF SY-SUBRC = 0.

    COMMIT WORK.

    ENDIF.

    ENDFORM.

    " UPDATE_ERROR_LOG

    =============

    regards

    Pranu

Add a comment
10|10000 characters needed characters exceeded

  • Posted on Jul 23, 2008 at 09:36 AM

    Based on the reply of Arthur I found the reason, or at least a workaround.

    The suggestion of IND_SECTOR was the hint, I never really checked the HEADDATA fields. IND_SECTOR is only needed for new materials, but for changes it's needed to select at least one view.

    In normal cases (also account_view availabe) all possible view were available, so I guess that is why it probably worked anyway. If I just check one view (eg MRP_VIEW) it works even if I want to change fields from other view that already exist.

    So ... problem solved for me (still need to change my programs 😊)

    Add a comment
    10|10000 characters needed characters exceeded

  • Before answering

    You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
    You must be Logged in to submit an answer.

    Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.