Hi All,
I have wriiten following code for material master upload . when i am trying to upload my flat file its being updated in database .But when i am trying to check in mm03 i am getting a error " Material xxxx does not exist in storage location xxxx of plant xxx." As i am fresher please help me out in resolving this issue.
LOOP AT itab .
* header data
wa_mathead-material = itab-material.
wa_mathead-ind_sector = itab-indstr_sec.
wa_mathead-matl_type = itab-matl_type.
wa_mathead-basic_view = 'X'.
wa_mathead-storage_view = 'X'.
wa_mathead-purchase_view = 'X'.
wa_mathead-mrp_view = 'X'.
wa_mathead-account_view = 'X'.
wa_mathead-quality_view = 'X'.
* material description
REFRESH it_makt.
wa_makt-langu = sy-langu.
wa_makt-matl_desc = itab-matl_desc .
APPEND wa_makt TO it_makt.
* clear wa_makt.
REFRESH it_tline.
gv_length = strlen( itab-pur_text ).
gv_count1 = gv_length DIV gv_count2.
gv_count3 = gv_length MOD gv_count2.
IF gv_count3 EQ 0.
ELSE.
gv_count1 = gv_count1 + 1.
ENDIF.
DO gv_count1 TIMES.
wa_tline-tdline = itab-pur_text+gv_count4(gv_count2).
APPEND wa_tline TO it_tline.
CLEAR: wa_tline.
gv_count4 = gv_count4 + gv_count2.
ENDDO.
REFRESH it_mltx.
* wa_mltx-applobject = 'MATERIAL' .
* wa_mltx-text_name = itab-material.
* wa_mltx-text_id = 'BEST'.
* wa_mltx-langu = sy-langu.
* wa_mltx-format_col = '*'.
LOOP AT it_tline INTO wa_tline.
wa_mltx-applobject = 'MATERIAL' .
wa_mltx-text_name = itab-material.
wa_mltx-text_id = 'BEST'.
wa_mltx-langu = sy-langu.
wa_mltx-format_col = '*'.
wa_mltx-text_line = wa_tline-tdline .
APPEND wa_mltx TO it_mltx.
CLEAR wa_mltx.
ENDLOOP.
* client data
CLEAR wa_mara.
wa_mara-base_uom = itab-unit_of_mesure.
wa_mara-matl_group = itab-matl_grp .
wa_mara-old_mat_no = itab-old_matno .
wa_mara-dsn_office = itab-desn_off .
* wa_mara-po_unit = itab-po_uom .
wa_mara-batch_mgmt = itab-batch_mgmt.
wa_mara-minremlife = itab-min_rem_life.
wa_mara-shelf_life = itab-tot_shelf_life .
wa_mara-period_ind_expiration_date = itab-period_ind_expiration_date.
CLEAR wa_marax.
wa_marax-base_uom = 'X'.
wa_marax-matl_group = 'X'.
wa_marax-old_mat_no = 'X'.
wa_marax-dsn_office = 'X'.
wa_marax-po_unit = 'X'.
wa_marax-batch_mgmt = 'X'.
wa_marax-minremlife = 'X'.
wa_marax-shelf_life = 'X'.
wa_marax-period_ind_expiration_date = 'X'.
* PLANTDATA
CLEAR wa_marc.
wa_marc-plant = itab-plant.
wa_marc-iss_st_loc = itab-storage_loc .
wa_marc-pur_group = itab-purc_grp.
wa_marc-auto_p_ord = itab-auto_pur_ord.
wa_marc-ind_post_to_insp_stock = itab-po_insp_stock.
wa_marc-mrp_type = itab-mrp_type.
wa_marc-reorder_pt = itab-reorder_pt.
wa_marc-mrp_ctrler = itab-mrp_ctrler.
wa_marc-lotsizekey = itab-lotsizekey.
wa_marc-fixed_lot = itab-fixed_lot_size.
wa_marc-plnd_delry = itab-plnd_delry.
wa_marc-period_ind = itab-period_ind.
wa_marc-availcheck = itab-availcheck.
wa_marc-profit_ctr = itab-profit_ctr.
CLEAR wa_marcx.
wa_marcx-plant = itab-plant.
wa_marcx-iss_st_loc = 'X'.
wa_marcx-pur_group = 'X'.
wa_marcx-auto_p_ord = 'X'.
wa_marcx-ind_post_to_insp_stock = 'X'.
wa_marcx-mrp_type = 'X'.
wa_marcx-reorder_pt = 'X'.
wa_marcx-mrp_ctrler = 'X'.
wa_marcx-lotsizekey = 'X'.
wa_marcx-fixed_lot = 'X'.
wa_marcx-plnd_delry = 'X'.
wa_marcx-period_ind = 'X'.
wa_marcx-availcheck = 'X'.
wa_marcx-profit_ctr = 'X'.
* VALUATION DATA
CLEAR wa_mbew.
wa_mbew-val_area = itab-plant.
wa_mbew-val_class = itab-val_class.
wa_mbew-price_ctrl = itab-price_ctrl.
wa_mbew-price_unit = itab-price_unit.
wa_mbew-moving_pr = itab-moving_pr.
CLEAR wa_mbewx.
wa_mbewx-val_area = itab-plant.
wa_mbewx-val_class = 'X'.
wa_mbewx-price_ctrl = 'X'.
wa_mbewx-price_unit = 'X'.
wa_mbewx-moving_pr = 'X'.
BREAK-POINT.
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
headdata = wa_mathead
clientdata = wa_mara
clientdatax = wa_marax
plantdata = wa_marc
plantdatax = wa_marcx
valuationdata = wa_mbew
valuationdatax = wa_mbewx
IMPORTING
return = it_return
TABLES
materialdescription = it_makt
materiallongtext = it_mltx.
BREAK-POINT.
IF sy-subrc = 0.
ENDIF.
IF it_return-type CA 'EA'.
WRITE :/ 'ERROR' , wa_return-message ,'FOR MATERIAL:', itab-material.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* WAIT =
* IMPORTING
* RETURN =
.
* WRITE :/ 'SUCCESSFULLY CREATED MATNR', itab-material.
ENDIF.
CLEAR: wa_mathead,it_return.
ENDLOOP.
PFA for my flat file for which i am using to upload.
Thanks and Regards
vamsi ippili.