‎2012 Jan 17 11:03 PM
Hi,
I am creating Material Master record using BAPI_MATERIAL_SAVEDATA. I am getting all material details from BAPI_MATERIAL_GET_ALL and then passing them to variables of BAPI_MATERIAL_SAVEDATA.
I can create successfully material, but Sales Views are not created, always display the message , Material not found in Storage location X of plant Y.
I am using loop because, I am having multiple storage locations for combination of plant, sales organization and
distribution channel.
LOOP AT it_mvke .
CALL FUNCTION 'BAPI_MATERIAL_GET_ALL'
EXPORTING
material = p_matnr1
comp_code = it_t001k-bukrs
val_area = it_mbew-bwkey
val_type = it_mbew-bwtar
plant = p_werks
salesorg = it_mvke-vkorg
distr_chan = it_mvke-vtweg
IMPORTING
clientdata = it_client
plantdata = it_plant
storagelocationdata = it_storage
valuationdata = it_valuation
salesdata = it_sales
TABLES
taxclassifications = it_tax_class
return = it_return.
it_header-material = lv_matnr.
it_header-matl_type = it_mara-mtart.
it_header-ind_sector = it_mara-mbrsh.
it_header-sales_view = 'X'.
MOVE-CORRESPONDING it_sales TO it_sales1.
MOVE-CORRESPONDING it_sales1 TO it_sales1x.
BEGIN OF I_D01K966423 Add Code
MOVE-CORRESPONDING it_client TO it_client1.
MOVE-CORRESPONDING it_client1 TO it_client1x.
it_client1-old_mat_no = lv_matnr1.
it_client1-pur_status = 'M2'.
it_client1-sal_status = 'Z1'.
it_client1-svalidfrom = sy-datum.
END OF I_D0K966423 Add Code
MOVE-CORRESPONDING it_plant TO it_plant1.
MOVE-CORRESPONDING it_plant1 TO it_plant1x.
Tax classification for Sales view
LOOP AT it_tax_class.
MOVE-CORRESPONDING it_tax_class TO it_tax_class1.
APPEND it_tax_class1.
CLEAR : it_tax_class, it_tax_class1.
ENDLOOP.
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
headdata = it_header
clientdata = it_client1
clientdatax = it_client1x
plantdata = it_plant1
plantdatax = it_plant1x
salesdata = it_sales1
salesdatax = it_sales1x
IMPORTING
return = it_return2
TABLES
taxclassifications = it_tax_class1[] " For Sales View
returnmessages = returnmsg2.
ENDLOOP.
‎2012 Jan 18 10:02 AM
Hi,
If you are giving a random material number, check if the material that your giving in selection screen exists in MARA table.
regards.
Aswath.
‎2012 Jan 18 10:59 AM
Hi,
Refer this program.
&----
*& Report ZBAPI_TEST1
*&
&----
*& Author :
*& Date : 18-01-2012
*& Purpose :
&----
*& Date Changed by Tag Description
*&
&----
report zbapi_TEST1.
*---tables used
tables:bapimathead,
bapi_makt,
bapi_mara,
bapi_marax.
*--declaration for internal table
data:begin of itab occurs 0,
material type bapimathead-material,
ind_sector(20),
matl_type type bapimathead-matl_type,
matl_group type bapi_mara-matl_group,
langu type bapi_makt-langu,
matl_desc type bapi_makt-matl_desc,
end of itab,
it_return like bapiret2,
it_bapi like bapi_makt occurs 0 with header line.
data: bapi_mvke type bapi_mvke,
bapi_mvkex type bapi_mvkex.
data: bapi_marc type bapi_marc,
bapi_marcx type bapi_marcx.
data: bapi_mard type bapi_mard,
bapi_mardx type bapi_mardx.
*---selection screen
parameters:p_file type ibipparms-path obligatory.
*---f4 help for the file from PC
at selection-screen on value-request for p_file.
perform get_f4help.
*--start-of-selection .
start-of-selection.
perform upload_file_itab.
perform call_bapi.
&----
*& Form GET_F4HELP
&----
form get_f4help .
call function 'F4_FILENAME'
exporting
program_name = syst-cprog
dynpro_number = syst-dynnr
importing
file_name = p_file. " get_f4help
endform. " GET_F4HELP
&----
*& Form UPLOAD_FILE_ITAB
&----
form upload_file_itab.
data: l_file type string.
l_file = p_file.
call function 'GUI_UPLOAD'
exporting
filename = l_file
filetype = 'ASC'
has_field_separator = 'X'
tables
data_tab = itab. " upload_file_itab
endform. " UPLOAD_FILE_ITAB
&----
*& Form CALL_BAPI
&----
form call_bapi .
loop at itab.
bapimathead-material = itab-material.
bapimathead-ind_sector = itab-ind_sector.
bapimathead-matl_type = itab-matl_type.
bapimathead-basic_view = 'X'.
bapimathead-sales_view = 'X'.
bapi_mara-matl_group = itab-matl_group.
bapi_mara-base_uom = 'KGS'.
bapi_marax-matl_group = 'X'.
bapi_marax-base_uom = 'X'.
bapi_marc-plant = bapi_marcx-plant = '1000'.
bapi_mard-plant = bapi_mardx-plant = '1000'.
bapi_mard-stge_loc = bapi_mardx-stge_loc = '0001'.
bapi_mvke-sales_org = '1000'.
bapi_mvke-distr_chan = '10'.
bapi_mvkex-sales_org = '1000'.
bapi_mvkex-distr_chan = '10'.
it_bapi-langu = itab-langu.
it_bapi-langu_iso = 'EN'.
it_bapi-matl_desc = itab-matl_desc.
append it_bapi.
endloop.
clear it_bapi.
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
salesdata = bapi_mvke
salesdatax = bapi_mvkex
importing
return = it_return
tables
materialdescription = it_bapi.
call function 'BAPI_TRANSACTION_COMMIT' .
*---this is the message type which indicates whether it is failed or succeded
write:/ it_return-type,it_return-message. " call_bapi
endform. " CALL_BAPI
Regards,
Guna.
‎2012 Jan 18 11:12 AM