2012 Oct 14 6:15 AM
Hi experts,
I have a requirement to extend material to other plants in MM01 once the material is created. So in user-exit(MGA00001) once user presseds save button in MM01, I will have following code in which will it will call my z-fm in update task:
* Release lock for update program, since same matnr will be used
CALL FUNCTION 'DEQUEUE_EMMARAE'
EXPORTING
matnr = wmara-matnr.
CALL FUNCTION 'ZFM_MM_EXTPLANT_SLOC' IN UPDATE TASK
EXPORTING
wmara = wmara "basic data
wmarc = wmarc "plant data
wmard = wmard "sloc data
wmbew = wmbew "accounting data
TABLES
stext = stext.
In my z-function module, I will call BAPI_MATERIAL_SAVEREPLICA, before replicate, it will read from a custom table and put into internal table(LT_ZTMMPLANT_EXT) to decide which plant to extend to.
lwa_headdata-function = lc_ins.
wa_headdata-material = wmara-matnr.
lwa_headdata-ind_sector = wmara-mbrsh.
lwa_headdata-matl_type = wmara-mtart.
lwa_headdata-purchase_view = lc_x
APPEND lwa_headdata TO lt_headdata.
LOOP AT lt_ztmmplant_ext INTO lwa_ztmmplant_ext.
* Populate MARC data to BAPIE1MARC
lwa_plantdata-function = lc_ins.
lwa_plantdata-material = wmara-matnr.
lwa_plantdata-plant = lwa_ztmmplant_ext-werks_ext.
APPEND lwa_plantdata TO lt_plantdata.
* Populate MARC data to BAPIE1MARCX
lwa_plantdatax-function = lc_ins.
lwa_plantdatax-material = wmara-matnr.
lwa_plantdatax-plant = lwa_ztmmplant_ext-werks_ext.
APPEND lwa_plantdatax TO lt_plantdatax.
ENDLOOP.
CALL FUNCTION 'BAPI_MATERIAL_SAVEREPLICA'
EXPORTING
noappllog = lc_x
nochangedoc = lc_x
testrun = space
inpfldcheck = space
TABLES
headdata = lt_headdata
plantdata = lt_plantdata "MARC
plantdatax = lt_plantdatax
returnmessages = lt_returnmessages.
My problem is the creation of material is success, but it doesn't get extended to the required plants. I didn't receive any update termination message. So what could be the problem lies? I have try the BAPI in se37 with the same sort of data and it success, but when called from user-exit, it wont. Any idea anyone?
Regards,
Marlson Siow
2012 Oct 14 10:00 AM
Change your FM from an update task to a RFC enabled FM and you customer-exit for a
* Release lock for update program, since same matnr will be used " <- remove
* CALL FUNCTION 'DEQUEUE_EMMARAE'
* EXPORTING
* matnr = wmara-matnr.
CALL FUNCTION 'ZFM_MM_EXTPLANT_SLOC' IN BACKGROUND TASK " change
EXPORTING
wmara = wmara "basic data
wmarc = wmarc "plant data
wmard = wmard "sloc data
wmbew = wmbew "accounting data
TABLES
stext = stext.
Then in your Z_FM, check RETURN result and add a call to BAPI_TRANSACTION_COMMIT as it will execute after update taks in another luw. If an error arise in the BAPI raise an error message, you will be able to read the message and restart the FM via transaction SM36.
You call also use a call of ENQUEUE_EMMARAE with WAIT at start of the Z_FM.
Regards,
Raymond
2012 Oct 14 6:59 AM
Hi,
Have u tried with LSMW/BDC? OR
BAPI LIKE THIS
'BAPI_MATERIAL_SAVEDATA'
scenario is same I think
http://wiki.sdn.sap.com/wiki/display/PLM/Example+Report+for+BAPI_MATERIAL_SAVEDATA
Otherwise u can search in SCN.
U will get many Threads for this.
Thanks
Gourav.
2012 Oct 14 7:32 AM
Hi Gourav,
I have search around the forum but none of them same with my case which is calling the BAPI in update task.
For your information, BAPI_MATERIAL_SAVEDATA is cater for 1 material, I need mass maintenance as I have to extend the material to several plants in one go.
Furthermore, I have test my FM in SE37 using the same sort of data and it works. However, when this FM is called from the user-exit, it doesn't work. Any idea why? Thanks
2012 Oct 14 7:48 AM
Hi,
Why U skipped this line in BAPI?
IMPORTING
return = " bapiret2 Return Parameter
Is there any reason?
I think for this reason in BAPI it is working, not in user exit.
Try it.
Thanks.
Gourav
2012 Oct 14 8:15 AM
still the same. I have added it as well. The changes doesn't reflect in MARC table.
The FM is working in se37, but when called in user-exit, it is not working.
2012 Oct 14 10:00 AM
Change your FM from an update task to a RFC enabled FM and you customer-exit for a
* Release lock for update program, since same matnr will be used " <- remove
* CALL FUNCTION 'DEQUEUE_EMMARAE'
* EXPORTING
* matnr = wmara-matnr.
CALL FUNCTION 'ZFM_MM_EXTPLANT_SLOC' IN BACKGROUND TASK " change
EXPORTING
wmara = wmara "basic data
wmarc = wmarc "plant data
wmard = wmard "sloc data
wmbew = wmbew "accounting data
TABLES
stext = stext.
Then in your Z_FM, check RETURN result and add a call to BAPI_TRANSACTION_COMMIT as it will execute after update taks in another luw. If an error arise in the BAPI raise an error message, you will be able to read the message and restart the FM via transaction SM36.
You call also use a call of ENQUEUE_EMMARAE with WAIT at start of the Z_FM.
Regards,
Raymond
2012 Oct 14 10:27 AM