‎2009 Feb 10 10:37 AM
Hello All,
i have some doubts.
we are searching for a BAPI which can help us to create one material in more than one plant in a single call to that BAPI.
we found BAPI_MATERIAL_SAVEREPLICA which used to transfer more than one materail at a time.
so is this BAPI can be useful to publish only one material with different plants>?
if possible can anyone provide me the input data in that BAPI so as to acquire tha same?
Abhijeet
‎2009 Feb 18 10:17 PM
Abhijeet,
The best way to use the FM is to create it for one material and extend it all plants as the error messages will be more meaningful to understand for a user.
Find below the sample code that might be useful for you in case you want to know how to populate the different structures in the BAPI.
Hope this clarifies your question.
Regards,
Hari
FORM z_post_data .
Populate the various bapi internal tables from the input internal
table.
LOOP AT i_input INTO wa_input.
v_counter = v_counter + 1.
Get the Internal material number
PERFORM get_material_num CHANGING l_fl_error.
IF l_fl_error NE c_x.
Build the Initial screen data
PERFORM initial_screen.
Build the Basic View data
PERFORM basic_view.
Fill default storage
PERFORM fill_storage.
Add these fields only if it is a new creation through avantis load
IF fl_load IS INITIAL.
Build the Sales data
PERFORM sales_view_data.
fill plant data -> fills up purchase, mrp and sales/plant views
PERFORM fill_marc.
Build the Accounting view for all locations
PERFORM accounting_view.
Fill the short text
PERFORM short_text.
ENDIF.
Call bapi save replica
PERFORM create_material.
IF v_counter >= p_commit.
CLEAR v_counter.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDIF.
PERFORM clear_data.
ENDIF. "Endif fl_load
CLEAR : wa_input,fl_load,v_matnr.
ENDLOOP. "Endloop i_input.
ENDFORM. " z_postdata
FORM get_material_num CHANGING p_fl_error TYPE any.
Local declarations
Internal tables
Material number
DATA : l_i_matnr TYPE STANDARD TABLE OF bapimatinr,
l_wa_matnr TYPE bapimatinr.
Work areas
BAPI Return message
DATA : l_wa_error TYPE bapireturn1.
Local variables
DATA : l_v_mattype TYPE bapimatdoa-matl_type, "Material type
l_v_indsec TYPE bapimatdoa-ind_sector. "Industry sector
Material type
l_v_mattype = c_zprt.
Industry sector
l_v_indsec = c_u.
Check if the material already exists in the system through MMS Upload
READ TABLE i_mmsavantis
INTO wa_mmsavantis
WITH KEY avantismatnr = wa_input-matnr
BINARY SEARCH.
Return check not required
READ TABLE i_matnr
INTO wa_matnr
WITH KEY mmsmatnr = wa_mmsavantis-mmsmatnr
BINARY SEARCH.
IF sy-subrc EQ 0.
fl_load = 'X'.
v_matnr = wa_matnr-sapmatnr.
ENDIF. "Endif sy-subrc
IF fl_load IS INITIAL.
Function module to generate the material number
CALL FUNCTION 'BAPI_MATERIAL_GETINTNUMBER'
EXPORTING
material_type = l_v_mattype
industry_sector = l_v_indsec
IMPORTING
return = l_wa_error
TABLES
material_number = l_i_matnr.
IF l_wa_error-type NE c_e
OR l_wa_error-type NE c_a.
READ TABLE l_i_matnr
INTO l_wa_matnr
INDEX 1.
IF sy-subrc EQ 0.
v_matnr = l_wa_matnr-material.
ELSE.
p_fl_error = 'X'.
ENDIF. "Endif sy-subrc
ELSE.
p_fl_error = 'X'.
ENDIF. "Endif l_wa_error.
ENDIF. "Endif fl_load
CLEAR : wa_mmsavantis,wa_matnr.
ENDFORM. "get_material_num
FORM initial_screen.
IF fl_load IS INITIAL.
Insert functionality
wa_headdata-function = c_ins.
ELSE.
Update functionality
wa_headdata-function = c_upd.
ENDIF.
Material number
wa_headdata-material = v_matnr.
Industry sector
wa_headdata-ind_sector = c_u.
Material type
wa_headdata-matl_type = c_zprt.
Basic view
wa_headdata-basic_view = c_x.
Sales view
wa_headdata-sales_view = c_x.
Purchase view
wa_headdata-purchase_view = c_x.
Account view
wa_headdata-account_view = c_x.
MRP vies
wa_headdata-mrp_view = c_x.
Storage view
wa_headdata-storage_view = c_x.
Append the header data to the bapi internal table
APPEND wa_headdata TO i_headdata.
Clear the work area.
CLEAR wa_headdata.
ENDFORM. " initial_screen
FORM basic_view .
IF fl_load IS INITIAL.
Insert functionality
wa_clientdata-function = c_ins.
Material group
Check if the Item type exists in the translation file
READ TABLE i_matgrp
INTO wa_matgrp
WITH KEY item = wa_input-itemtype
BINARY SEARCH.
READ TABLE i_matgrp
INTO wa_matgrp
WITH KEY matnr = wa_input-matnr.
Return check not required
Move material group
wa_clientdata-matl_group = wa_matgrp-matkl.
Material number
wa_clientdata-material = v_matnr.
Unit of measure
READ TABLE i_unit
INTO wa_unit
WITH KEY legaunit = wa_input-unit
BINARY SEARCH.
Return check not required
Convert the Units of Measure
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
EXPORTING
input = wa_unit-sapunit
language = sy-langu
IMPORTING
output = wa_unit-sapunit
EXCEPTIONS
unit_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
SKIP.
ENDIF.
wa_clientdata-base_uom = wa_unit-sapunit.
Unit of weight
wa_clientdata-unit_of_wt = c_lb.
Lab/ Office
wa_clientdata-dsn_office = c_h20.
X-Plant Material status If non-null value. move 01
IF wa_input-status IS NOT INITIAL.
wa_clientdata-pur_status = c_01.
ELSE.
CLEAR wa_clientdata-pur_status.
ENDIF. "Endif wa_input-status
Division
wa_clientdata-division = c_99.
Storage Conditions.
wa_clientdata-stor_conds = c_storconds.
Item category group
wa_clientdata-item_cat = c_norm.
Purchasing value key
wa_clientdata-pur_valkey = c_1.
Manufacturer part profile
wa_clientdata-manuf_prof = c_0001.
Transportation group
wa_clientdata-trans_grp = c_0001.
Industry standard description populated with legacy matnr
wa_clientdata-std_descr = wa_input-matnr.
ELSE.
Insert functionality
wa_clientdata-function = c_upd.
Material number
wa_clientdata-material = v_matnr.
Industry standard description populated with legacy matnr
wa_clientdata-std_descr = wa_input-matnr.
ENDIF.
APPEND wa_clientdata TO i_clientdata.
CLEAR wa_clientdata.
Append the change table structure
IF fl_load IS INITIAL.
wa_clientdatax-function = c_ins.
wa_clientdatax-material = v_matnr.
wa_clientdatax-matl_group = c_x.
wa_clientdatax-base_uom = c_x.
wa_clientdatax-old_mat_no = c_x.
wa_clientdatax-extmatlgrp = c_x.
wa_clientdatax-unit_of_wt = c_x.
IF wa_input-status IS NOT INITIAL.
wa_clientdatax-pur_status = c_x.
ELSE.
CLEAR wa_clientdatax-pur_status.
ENDIF. "Endif wa_clientdata
wa_clientdatax-division = c_x.
wa_clientdatax-std_descr = c_x.
wa_clientdatax-pur_valkey = c_x.
wa_clientdatax-manuf_prof = c_x.
wa_clientdatax-dsn_office = c_x .
Storage Conditions.
wa_clientdatax-stor_conds = c_x.
wa_clientdatax-trans_grp = c_x.
ELSE.
wa_clientdatax-function = c_upd.
wa_clientdatax-material = v_matnr.
wa_clientdatax-std_descr = c_x.
ENDIF.
*End of Change
APPEND wa_clientdatax TO i_clientdatax.
CLEAR wa_clientdatax .
CLEAR : wa_matgrp,wa_unit.
ENDFORM. " basic_view
FORM sales_view_data .
Insert functionality
wa_salesdata-function = c_ins.
Material number
wa_salesdata-material = v_matnr.
Sales organisation
wa_salesdata-sales_org = c_1001.
Distribution channel
wa_salesdata-distr_chan = c_01.
Item categroy group
wa_salesdata-item_cat = c_norm.
Account assignment
Get the account assignment from the external file
READ TABLE i_account
INTO wa_account
WITH KEY legaacct = wa_input-account
BINARY SEARCH.
Return check not required
Move the account assignment to the BAPI
wa_salesdata-acct_assgt = wa_account-sapacct.
APPEND wa_salesdata TO i_salesdata.
CLEAR :wa_salesdata,wa_account.
Updating the Sales data change table
Insert functionality
wa_salesdatax-function = c_ins.
Insert material
wa_salesdatax-material = v_matnr.
Insert sales organisation
wa_salesdatax-sales_org = c_1001.
Insert Distribution channel
wa_salesdatax-distr_chan = c_01.
Insert item category
wa_salesdatax-item_cat = c_x.
Insert delivering plant
wa_salesdatax-delyg_plnt = c_x.
Insert account assignment
wa_salesdatax-acct_assgt = c_x.
APPEND wa_salesdatax TO i_salesdatax.
CLEAR wa_salesdatax.
ENDFORM. " sales_view_data
FORM fill_marc .
Plant general plant data
Insert functionality
wa_plantdata-function = c_ins.
Plant
wa_plantdata-plant = c_9999.
Material number
wa_plantdata-material = v_matnr.
Determine the Purchasing group.
READ TABLE i_purgrp
INTO wa_purgrp
WITH KEY buyer = wa_input-buyer
BINARY SEARCH.
Move the purchasing group
wa_plantdata-pur_group = wa_purgrp-group.
Automatic PO is required.
wa_plantdata-auto_p_ord = c_x.
SourceList is Unchecked
CLEAR : wa_plantdata-sourcelist.
Profit center
wa_plantdata-profit_ctr = c_profitctr.
Issue Storage Location
wa_plantdata-iss_st_loc = c_0001.
Storage relate data
wa_plantdata-cc_ph_inv = c_c.
CLEAR : wa_plantdata-cc_ph_inv .
SourceList is Required
wa_plantdata-sourcelist = c_x.
Storage relate data
wa_plantdata-cc_ph_inv = c_c.
MRP related data
Availability Check
wa_plantdata-availcheck = c_02.
ABC indicator
wa_plantdata-abc_id = c_c.
MRP type
wa_plantdata-mrp_type = c_nd.
GR Processing time
wa_plantdata-gr_pr_time = c_2.
Lot Size Key
wa_plantdata-lotsizekey = c_ex.
Loading group
wa_plantdata-loadinggrp = c_0001.
Dependent requirements id. Mandatory field not in mapping
wa_plantdata-dep_req_id = c_2.
Append the plant data
APPEND wa_plantdata TO i_plantdata.
CLEAR :wa_plantdata,wa_purgrp.
Append the change table
wa_plantdatax-function = c_ins.
wa_plantdatax-plant = c_9999.
wa_plantdatax-material = v_matnr.
wa_plantdatax-loadinggrp = c_x.
wa_plantdatax-pur_group = c_x.
wa_plantdatax-auto_p_ord = c_x.
wa_plantdatax-sourcelist = c_x.
wa_plantdatax-mrp_ctrler = c_x.
wa_plantdatax-mrp_type = c_x.
wa_plantdatax-lotsizekey = c_x.
wa_plantdatax-gr_pr_time = c_x.
Profit center
wa_plantdatax-profit_ctr = c_x.
Issue Storage Location
wa_plantdatax-iss_st_loc = c_x.
wa_plantdatax-availcheck = c_x.
wa_plantdatax-pur_group = c_x.
wa_plantdatax-cc_ph_inv = c_x.
wa_plantdatax-abc_id = c_x.
wa_plantdatax-dep_req_id = c_x.
APPEND wa_plantdatax TO i_plantdatax.
CLEAR wa_plantdatax.
ENDFORM. " fill_marc
FORM accounting_view .
Insert functionality
wa_valuationdata-function = c_ins.
Material number
wa_valuationdata-material = v_matnr.
Plant valuation area " valuation area is the plant
wa_valuationdata-val_area = c_9999.
Valuation calls
wa_valuationdata-val_class = c_gas.
Price control
wa_valuationdata-price_ctrl = c_v.
Price unit
wa_valuationdata-price_unit = c_1.
Average moving price
wa_valuationdata-moving_pr = wa_input-price.
Append valuation data
APPEND wa_valuationdata TO i_valuationdata.
CLEAR wa_valuationdata.
Change table for valuation data
wa_valuationdatax-function = c_ins.
wa_valuationdatax-material = v_matnr.
wa_valuationdatax-val_area = c_9999.
wa_valuationdatax-val_class = c_x.
wa_valuationdatax-price_ctrl = c_x.
wa_valuationdatax-price_unit = c_x.
wa_valuationdatax-moving_pr = c_x.
APPEND wa_valuationdatax TO i_valuationdatax.
CLEAR wa_valuationdatax.
ENDFORM. " accounting_view
FORM short_text .
Insert functionality
wa_materialdescription-function = c_ins.
Material number
wa_materialdescription-material = v_matnr.
Language
wa_materialdescription-langu = sy-langu.
Material description
wa_materialdescription-matl_desc = wa_input-desc.
APPEND wa_materialdescription TO i_materialdescription.
CLEAR wa_materialdescription.
ENDFORM. " short_text
Create the material using the BAPI 'BAPI_MATERIAL_SAVEREPLICA'
----
FORM create_material .
Local variables for the BAPI posting
DATA : l_v_noappllog TYPE bapie1global_data-no_appl_log ,
l_v_nochangedoc TYPE bapie1global_data-no_change_doc ,
l_v_testrun TYPE bapie1global_data-testrun ,
l_v_inpfldcheck TYPE bapie1global_data-inp_fld_check .
FM to create the material 'BAPI_MATERIAL_SAVEREPLICA'
CALL FUNCTION 'BAPI_MATERIAL_SAVEREPLICA'
EXPORTING
noappllog = l_v_noappllog
nochangedoc = l_v_nochangedoc
testrun = l_v_testrun
inpfldcheck = l_v_inpfldcheck
IMPORTING
return = wa_return
TABLES
headdata = i_headdata
clientdata = i_clientdata
clientdatax = i_clientdatax
plantdata = i_plantdata
plantdatax = i_plantdatax
storagelocationdata = i_storagelocationdata
storagelocationdatax = i_storagelocationdatax
valuationdata = i_valuationdata
valuationdatax = i_valuationdatax
salesdata = i_salesdata
salesdatax = i_salesdatax
materialdescription = i_materialdescription
taxclassifications = i_taxclassifications
materiallongtext = i_materiallongtext
returnmessages = i_returnmessages.
Do the post processing of the posting.
PERFORM z_post_processing.
ENDFORM. " create_material
‎2009 Mar 02 10:13 AM