‎2007 May 23 8:20 AM
Hi all,
I am calling bapi_material_save_data f.m in one of my custom function module i am getting an error message " field matnr has been transferred inconsistently or is blank'
here is my code
FUNCTION z_createupdate_material1.
*"----
""Local interface:
*" IMPORTING
*" VALUE(MATERIAL) TYPE STRING OPTIONAL
*" VALUE(PLANTVALUE) TYPE STRING OPTIONAL
*" VALUE(MATERIALTYPE) TYPE STRING OPTIONAL
*" VALUE(MATERIALGROUP) TYPE STRING OPTIONAL
*" VALUE(MANUFACTURERCODE) TYPE STRING OPTIONAL
*" VALUE(MANUFACTURERPARTNUM) TYPE STRING OPTIONAL
*" VALUE(CYCLECOUNTPHYSICALINVENTORY) TYPE STRING OPTIONAL
*" VALUE(ISSUEUNITOFMEASUER) TYPE STRING OPTIONAL
*" VALUE(WHEREUSEDORPMTAGNUMBER) TYPE STRING OPTIONAL
*" VALUE(PROCUREMENTTYPE) TYPE STRING OPTIONAL
*" VALUE(VALUATIONCATEGORY) TYPE STRING OPTIONAL
*" VALUE(PLANTSPECIFICMATERIALSTATUS) TYPE STRING OPTIONAL
*" VALUE(MRPTYPE) TYPE STRING OPTIONAL
*" VALUE(MRPCONTROLLER) TYPE STRING OPTIONAL
*" VALUE(REORDERPOINT) TYPE STRING OPTIONAL
*" VALUE(STORAGECONDITIONS) TYPE STRING OPTIONAL
*" VALUE(SAFETYSTOCK) TYPE STRING OPTIONAL
*" VALUE(MAXIMUMSTOCK) TYPE STRING OPTIONAL
*" VALUE(LOTSIZEKEY) TYPE STRING OPTIONAL
*" VALUE(STORAGELOCATION) TYPE STRING OPTIONAL
*" VALUE(PROFITCENTER) TYPE STRING OPTIONAL
*" VALUE(SPECIALPROCUREMENT) TYPE STRING OPTIONAL
*" VALUE(SCHEDMARGINKEY) TYPE STRING OPTIONAL
*" VALUE(AVAILABILITYCHECK) TYPE STRING OPTIONAL
*" VALUE(PRICECONTROL) TYPE STRING OPTIONAL
*" VALUE(GRPROCESSINGTIME) TYPE STRING OPTIONAL
*" VALUE(VALUATIONCLASS) TYPE STRING OPTIONAL
*" VALUE(PURCHASINGGROUP) TYPE STRING OPTIONAL
*" VALUE(INDUSTRY) TYPE STRING OPTIONAL
*" VALUE(HAZARDOUSMATERIALNUMBER) TYPE STRING OPTIONAL
*" VALUE(ABCINDICATOR) TYPE STRING OPTIONAL
*" VALUE(ORDERUNITOFMEASURE) TYPE STRING OPTIONAL
*" VALUE(MINIMUMLOTSIZE) TYPE STRING OPTIONAL
*" VALUE(CONVERSIONNUMERATOR) TYPE STRING OPTIONAL
*" VALUE(CONVERSIONDENOMINATOR) TYPE STRING OPTIONAL
*" VALUE(PLANNEDDELIVERYTIME) TYPE STRING OPTIONAL
*" VALUE(PURCHASINGVALUEKEY) TYPE STRING OPTIONAL
*" VALUE(ROUNDINGPROFILE) TYPE STRING OPTIONAL
*" VALUE(AUTOMATICPURCHASEORDER) TYPE STRING OPTIONAL
*" VALUE(UNITPRICE) TYPE STRING OPTIONAL
*" VALUE(LONGTEXT) TYPE STRING OPTIONAL
*" VALUE(MATERIALDESCRIPTION) TYPE STRING OPTIONAL
*" EXPORTING
*" VALUE(SAPSTATUSCODE) TYPE STRING
*" VALUE(SAPERRORMESSAGE) TYPE STRING
*" VALUE(MATERIALNUMBER) TYPE STRING
*"----
--
DATA: v_char TYPE i VALUE '40',
v_index TYPE i,
v_length TYPE i,
v_tabix(2) VALUE '40',
s_string(40),
v_last TYPE i,
p_char TYPE i VALUE '132',
p_index TYPE i,
p_length TYPE i,
p_tabix(5) VALUE '132',
p_string(132),
p_last TYPE i,
P_mat(18) type n.
--
DATA:mtype LIKE bapimatdoa-matl_type,
v_mat LIKE bapi1003_key-object,
isector LIKE bapimatdoa-ind_sector VALUE 'O',
t_material LIKE bapimatinr OCCURS 0 WITH HEADER LINE,
return1 LIKE bapireturn1 ,
allocvaluesnum TYPE bapi1003_alloc_values_num OCCURS 0 WITH HEADER LINE,
allocvaluescurr TYPE bapi1003_alloc_values_curr OCCURS 0 WITH HEADER LINE,
materialdescription1 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,
materiallongtext LIKE bapi_mltx OCCURS 0 WITH HEADER LINE,
allocvalueschar LIKE bapi1003_alloc_values_char OCCURS 0 WITH HEADER LINE,
headdata LIKE bapimathead,
clientdata LIKE bapi_mara,
clientdatax LIKE bapi_marax,
plantdata LIKE bapi_marc,
plantdatax LIKE bapi_marcx,
storagelocationdata LIKE bapi_mard,
storagelocationdatax LIKE bapi_mardx,
valuationdata LIKE bapi_mbew,
valuationdatax LIKE bapi_mbewx,
return TYPE bapiret2 OCCURS 0 WITH HEADER LINE.
DATA :BEGIN OF itab OCCURS 0,
value_char LIKE bapi1003_alloc_values_char-value_char,
END OF itab.
DATA:BEGIN OF t_refr OCCURS 0,
val_type(10) ,
END OF t_refr.
--
IF material = space.
----
--
IF materialtype = 'VEND' OR materialtype = 'HIBE ' OR materialtype = 'REFR'.
MOVE materialtype TO mtype.
CALL FUNCTION 'BAPI_STDMATERIAL_GETINTNUMBER'
EXPORTING
material_type = mtype
industry_sector = isector
required_numbers = 1
IMPORTING
return = return1
TABLES
material_number = t_material.
--
IF t_material-material = space OR t_material-material IS INITIAL.
MOVE return1-type TO sapstatuscode.
MOVE return1-message TO saperrormessage.
EXIT.
ELSE.
MOVE t_material-material TO material.
ENDIF.
--
ELSE.
sapstatuscode = 'E'.
saperrormessage = 'Invalid Material Type'.
saperrormessage = headdata-matl_type.
EXIT.
ENDIF.
ELSE.
sapstatuscode = 'E'.
saperrormessage = 'Material Number Should be blank'.
saperrormessage = headdata-matl_type.
EXIT.
ENDIF.
--
MOVE material TO headdata-material.
headdata-basic_view = 'X'.
headdata-mrp_view = 'X'.
headdata-purchase_view = 'X'.
headdata-forecast_view = 'X'.
headdata-storage_view = 'X'.
headdata-account_view = 'X'.
headdata-ind_sector = industry.
headdata-matl_type = materialtype.
clientdata-matl_group = materialgroup.
clientdata-base_uom = issueunitofmeasuer.
clientdata-mfr_no = manufacturercode .
clientdata-manu_mat = manufacturerpartnum .
clientdata-stor_conds = storageconditions.
clientdata-haz_mat_no = hazardousmaterialnumber.
clientdatax-matl_group = materialgroup.
clientdatax-base_uom = issueunitofmeasuer.
clientdatax-mfr_no = manufacturercode .
clientdatax-stor_conds = storageconditions.
clientdatax-manu_mat = manufacturerpartnum .
clientdatax-haz_mat_no = hazardousmaterialnumber.
plantdata-plant = plantvalue.
plantdata-proc_type = procurementtype .
plantdata-pur_status = plantspecificmaterialstatus.
plantdata-mrp_type = mrptype .
plantdata-mrp_ctrler = mrpcontroller.
plantdata-safety_stk = safetystock .
plantdata-minlotsize = maximumstock.
plantdata-lotsizekey = lotsizekey.
plantdata-cc_ph_inv = cyclecountphysicalinventory.
plantdata-sm_key = schedmarginkey.
plantdata-gr_pr_time = grprocessingtime.
plantdata-pur_group = purchasinggroup .
plantdata-abc_id = abcindicator .
plantdata-minlotsize = minimumlotsize.
plantdata-plnd_delry = planneddeliverytime .
plantdata-round_prof = roundingprofile.
plantdata-auto_p_ord = automaticpurchaseorder .
plantdata-profit_ctr = profitcenter .
plantdata-reorder_pt = reorderpoint .
plantdata-availcheck = availabilitycheck .
plantdata-spproctype = specialprocurement .
plantdatax-plant = plantvalue.
plantdatax-proc_type = procurementtype .
plantdatax-pur_status = plantspecificmaterialstatus.
plantdatax-mrp_type = mrptype .
plantdatax-mrp_ctrler = mrpcontroller.
plantdatax-safety_stk = safetystock .
plantdatax-minlotsize = maximumstock.
plantdatax-lotsizekey = lotsizekey.
plantdatax-cc_ph_inv = cyclecountphysicalinventory.
plantdatax-sm_key = schedmarginkey.
plantdatax-gr_pr_time = grprocessingtime.
plantdatax-pur_group = purchasinggroup .
plantdatax-abc_id = abcindicator .
plantdatax-minlotsize = minimumlotsize.
plantdatax-plnd_delry = planneddeliverytime .
plantdatax-round_prof = roundingprofile.
plantdatax-auto_p_ord = automaticpurchaseorder .
plantdatax-profit_ctr = profitcenter .
plantdatax-reorder_pt = reorderpoint .
plantdatax-availcheck = availabilitycheck .
plantdatax-spproctype = specialprocurement .
storagelocationdata-stge_loc = storagelocation.
storagelocationdatax-stge_loc = storagelocation.
valuationdata-price_ctrl = pricecontrol.
valuationdata-val_class = valuationclass.
valuationdata-price_unit = unitprice .
valuationdata-val_cat = 'F'.
valuationdata-price_ctrl = pricecontrol.
valuationdatax-val_class = valuationclass.
valuationdatax-price_unit = unitprice .
valuationdatax-val_cat = 'F'.
clientdatax-pur_valkey = '5%'.
clientdata-pur_valkey = '5%'.
plantdata-gr_pr_time = '75'.
plantdatax-gr_pr_time = '75'.
plantdata-sm_key = '000'.
plantdatax-sm_key = '000'.
plantdata-availcheck = '02'.
plantdatax-availcheck = '02'.
valuationdata-price_ctrl = 'V'.
valuationdata-val_area = plantvalue.
valuationdata-val_class = valuationclass.
valuationdata-val_cat = valuationcategory.
valuationdatax-price_ctrl = 'V'.
valuationdatax-val_area = plantvalue.
unitsofmeasure-alt_unit = orderunitofmeasure.
unitsofmeasure-numerator = conversionnumerator.
unitsofmeasure-denominatr = conversiondenominator.
APPEND unitsofmeasure.
unitsofmeasurex-alt_unit = orderunitofmeasure.
unitsofmeasurex-numerator = conversionnumerator.
unitsofmeasurex-denominatr = conversiondenominator.
APPEND unitsofmeasurex.
--
--
v_length = STRLEN( materialdescription ).
DO .
IF NOT v_char GT v_length.
MOVE materialdescription+v_index(v_tabix) TO s_string.
MOVE s_string TO materialdescription1-matl_desc.
MOVE 'EN' TO materialdescription1-langu.
APPEND materialdescription1.
CLEAR s_string.
v_index = v_index + 40.
v_char = v_char + 40.
ELSE.
EXIT.
ENDIF.
ENDDO.
IF v_index LT v_length .
v_last = v_length - v_index .
MOVE materialdescription+v_index(v_last) TO s_string.
move s_string to materialdescription1-matl_desc.
MOVE 'EN' TO materialdescription1-langu.
APPEND materialdescription1.
CLEAR s_string.
ENDIF.
--
--
P_mat = material.
p_length = STRLEN( longtext ).
DO .
IF NOT p_char GT p_length.
MOVE longtext+p_index(p_tabix) TO p_string.
MOVE p_string TO materiallongtext-text_line.
materiallongtext-TEXT_NAME = P_mat.
materiallongtext-TEXT_ID = 'GRUN'.
materiallongtext-LANGU = 'EN'.
APPEND materiallongtext.
CLEAR p_string.
p_index = p_index + 132.
p_char = p_char + 132.
ELSE.
EXIT.
ENDIF.
ENDDO.
IF p_index LT p_length .
p_last = p_length - p_index .
MOVE materiallongtext-text_line+p_index(p_last) TO p_string.
APPEND materiallongtext.
CLEAR p_string.
ENDIF.
--
IF ( materialtype <> 'REFR' AND ( PLANTVALUE <> '7700' or plantvalue <>'7810') ).
--
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
headdata = headdata
clientdata = clientdata
clientdatax = clientdatax
plantdata = plantdata
plantdatax = plantdatax
storagelocationdata = storagelocationdata
storagelocationdatax = storagelocationdatax
valuationdata = valuationdata
valuationdatax = valuationdatax
IMPORTING
return = return
TABLES
materialdescription = materialdescription1
unitsofmeasure = unitsofmeasure
unitsofmeasurex = unitsofmeasurex
materiallongtext = materiallongtext.
IF sy-subrc <> 0.
MOVE return-type TO sapstatuscode.
MOVE return-message TO saperrormessage.
EXIT.
ENDIF.
IF return-type = 'S'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT =
IMPORTING
RETURN =
.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
IMPORTING
RETURN =
.
MOVE return-message TO saperrormessage .
MOVE return-type TO sapstatuscode.
EXIT.
ENDIF.
----
ELSEIF ( materialtype = 'REFR' AND ( plantvalue = '7700' OR plantvalue = '7810' ) ).
t_refr-val_type = 'NEW'.
APPEND t_refr.
t_refr-val_type = 'BROKEN'.
APPEND t_refr.
t_refr-val_type = 'REPAIRED'.
APPEND t_refr.
LOOP AT t_refr.
valuationdata-val_type = t_refr-val_type.
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
headdata = headdata
clientdata = clientdata
clientdatax = clientdatax
plantdata = plantdata
plantdatax = plantdatax
storagelocationdata = storagelocationdata
storagelocationdatax = storagelocationdatax
valuationdata = valuationdata
valuationdatax = valuationdatax
IMPORTING
return = return
TABLES
materialdescription = materialdescription1
unitsofmeasure = unitsofmeasure
unitsofmeasurex = unitsofmeasurex
materiallongtext = materiallongtext.
IF sy-subrc <> 0.
MOVE return-type TO sapstatuscode.
MOVE return-message TO saperrormessage.
EXIT.
ENDIF.
IF return-type = 'S'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT =
IMPORTING
RETURN =
.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
IMPORTING
RETURN =
.
MOVE return-message TO saperrormessage .
MOVE return-type TO sapstatuscode.
EXIT.
ENDIF.
ENDLOOP.
ENDIF.
--
SPLIT whereusedorpmtagnumber AT ',' INTO TABLE itab.
LOOP AT itab.
MOVE-CORRESPONDING itab TO allocvalueschar.
APPEND allocvalueschar.
ENDLOOP.
v_mat = t_material-material .
CALL FUNCTION 'BAPI_OBJCL_GETDETAIL'
EXPORTING
objectkey = v_mat
objecttable = 'MARA'
classnum = 'WHERE_USED'
classtype = '001'
keydate = sy-datum
UNVALUATED_CHARS = ' '
language = sy-langu
IMPORTING
STATUS =
STANDARDCLASS =
TABLES
allocvaluesnum = allocvaluesnum
allocvalueschar = allocvalueschar
allocvaluescurr = allocvaluescurr
return = return.
ENDIF.
IF sy-subrc <> 0.
LOOP AT return .
MOVE return-type TO sapstatuscode.
MOVE return-message TO saperrormessage.
EXIT.
ENDLOOP.
ENDIF.
IF sapstatuscode = space.
sapstatuscode = 'S'.
CONCATENATE 'Material Master Of ' t_material-material 'CREATED ' INTO saperrormessage SEPARATED BY space.
ENDIF.
----------- Extend Plants 7700,7810 to 7770,7850----------------------------*
IF ( plantvalue = '7700' OR plantvalue = '7810') .
CLEAR: headdata,clientdata,clientdatax,plantdata,plantdatax,storagelocationdata,storagelocationdatax,
valuationdata,valuationdatax,unitsofmeasure,materialdescription1,unitsofmeasure,unitsofmeasurex,
materiallongtext.
REFRESH:materialdescription1,unitsofmeasure,unitsofmeasurex,materiallongtext.
--
IF ( materiAltype <> 'REFR' AND ( plantvalue = '7700' OR plantvalue = '7810') ).
headdata-basic_view = 'X'.
headdata-mrp_view = 'X'.
headdata-ind_sector = industry.
headdata-matl_type = materialtype.
plantdata-plant = plantvalue.
plantdata-mrp_type = mrptype .
plantdata-mrp_ctrler = mrpcontroller.
plantdata-lotsizekey = lotsizekey.
plantdata-sm_key = '000'.
plantdata-gr_pr_time = '75'.
plantdata-pur_group = purchasinggroup .
plantdata-plnd_delry = planneddeliverytime .
plantdata-availcheck = '02' .
plantdata-spproctype = specialprocurement.
plantdatax-plant = plantvalue.
plantdatax-mrp_type = mrptype .
plantdatax-mrp_ctrler = mrpcontroller.
plantdatax-lotsizekey = lotsizekey.
plantdatax-sm_key = '000'.
plantdatax-gr_pr_time = '75'.
plantdatax-pur_group = purchasinggroup .
plantdatax-plnd_delry = planneddeliverytime .
plantdatax-availcheck = '02' .
plantdatax-spproctype = specialprocurement .
--
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
headdata = headdata
clientdata = clientdata
clientdatax = clientdatax
plantdata = plantdata
plantdatax = plantdatax
storagelocationdata = storagelocationdata
storagelocationdatax = storagelocationdatax
valuationdata = valuationdata
valuationdatax = valuationdatax
IMPORTING
return = return
TABLES
materialdescription = materialdescription1
unitsofmeasure = unitsofmeasure
unitsofmeasurex = unitsofmeasurex
materiallongtext = materiallongtext.
IF sy-subrc <> 0.
MOVE return-type TO sapstatuscode.
MOVE return-message TO saperrormessage.
EXIT.
ENDIF.
IF return-type = 'S'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT =
IMPORTING
RETURN =
.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
IMPORTING
RETURN =
.
MOVE return-message TO saperrormessage .
MOVE return-type TO sapstatuscode.
EXIT.
ENDIF.
ENDIF.
--
ELSEIF ( materialtype = 'REFR' AND ( plantvalue = '7700' OR plantvalue = '7810') ).
headdata-basic_view = 'X'.
headdata-mrp_view = 'X'.
headdata-ind_sector = industry.
headdata-matl_type = materialtype.
plantdata-plant = plantvalue.
plantdata-mrp_type = mrptype .
plantdata-sm_key = '000'.
plantdata-gr_pr_time = '75'.
plantdata-pur_group = purchasinggroup .
plantdata-plnd_delry = planneddeliverytime .
plantdata-availcheck = '02' .
plantdata-spproctype = '70'.
plantdatax-plant = plantvalue.
plantdatax-mrp_type = mrptype .
plantdatax-mrp_ctrler = 'PD'.
plantdatax-lotsizekey = 'EX'.
plantdatax-sm_key = '000'.
plantdatax-gr_pr_time = '75'.
plantdatax-pur_group = purchasinggroup .
plantdatax-plnd_delry = planneddeliverytime .
plantdatax-availcheck = '02' .
plantdatax-spproctype = specialprocurement.
PLANTDATA-MRP_CTRLER = 'PD'.
plantdata-lotsizekey = 'EX'.
plantdata-spproctype = '70'.
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
headdata = headdata
clientdata = clientdata
clientdatax = clientdatax
plantdata = plantdata
plantdatax = plantdatax
storagelocationdata = storagelocationdata
storagelocationdatax = storagelocationdatax
valuationdata = valuationdata
valuationdatax = valuationdatax
IMPORTING
return = return
TABLES
materialdescription = materialdescription1
unitsofmeasure = unitsofmeasure
unitsofmeasurex = unitsofmeasurex
materiallongtext = materiallongtext.
IF sy-subrc <> 0.
MOVE return-type TO sapstatuscode.
MOVE return-message TO saperrormessage.
EXIT.
ENDIF.
IF return-type = 'S'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT =
IMPORTING
RETURN =
.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
IMPORTING
RETURN =
.
MOVE return-message TO saperrormessage .
MOVE return-type TO sapstatuscode.
EXIT.
ENDIF.
ENDIF.
ENDIF.
ENDFUNCTION.
Can any one please let me know how can i overcome from this error message?
‎2007 May 23 8:27 AM
Hi,
The error suggests about the meterial number..Please check if u are passing correct material number in alll the FM'S u r using...
Regards,
Nagaraj