Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Calling BAPI_MATERIAL_SAVEREPLICA in update task

Former Member
0 Likes
5,024

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

1 ACCEPTED SOLUTION
Read only

RaymondGiuseppi
Active Contributor
0 Likes
2,282

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

6 REPLIES 6
Read only

gouravkumar64
Active Contributor
0 Likes
2,282

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.

Read only

0 Likes
2,282

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

Read only

0 Likes
2,282

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

Read only

0 Likes
2,282

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.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
2,283

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

Read only

0 Likes
2,282

Thanks, it work like a charm.