‎2009 Aug 04 6:15 AM
Hi Experts,
I have a requirement where I have to delete a material in the background. I understand that this is possible through BAPI_MATERIAL_DELETE but this bapi calls the transaction MM06. . Is there any other BAPI so that I can delete the material Directly in background. Any suggestion on this will be very helpful. I want to achieve this through BAPI only.
Thanx in advance,
Rajeev.
‎2009 Aug 04 9:42 AM
Hi Dzed,
when I m trying to delete material through this BAPI bu marking the flag for deletion, it is not being flagged for deletion. I can see this material in MM03. Please help me on this.
‎2009 Aug 04 6:20 AM
Hello
Use BAPI BAPI_MATERIAL_SAVEDATA
BAPI_MARA-DEL_FLAG - Flag Material for Deletion at Client Level
BAPI_MARC-DEL_FLAG - Flag Material for Deletion at Plant Level
BAPI_MARD-DEL_FLAG - Flag Material for Deletion at Storage Location Level
BAPI_MBEW-DEL_FLAG - Deletion flag for all material data of a valuation type
Also do not forget to fill structures BAPI_MARAX, BAPI_MARCX etc.
‎2009 Aug 04 6:20 AM
‎2009 Aug 04 6:21 AM
link:[http://abap.wikiprog.com/wiki/BAPI_MATERIAL_MAINTAINDATA_RT]
‎2009 Aug 04 6:22 AM
Hi,
Material can't be deleted but you can only mark the material for deletion.
You might have to write BDC of t.code MM06 for marking material for deletion.
Thanks.
‎2009 Aug 04 6:24 AM
Hi Dzed,
Can you please tell me that how we can use BAPI_MATERIAL_SAVEDATA to delete the material?
‎2009 Aug 04 6:30 AM
‎2009 Aug 04 7:25 AM
Hello
Example for delete material on plant level:
DATA: XHEADDATA LIKE BAPIMATHEAD OCCURS 0 WITH HEADER LINE,
XPLANTDATA LIKE BAPI_MARC OCCURS 0 WITH HEADER LINE,
XPLANTDATAX LIKE BAPI_MARCX OCCURS 0 WITH HEADER LINE,
XRETURN LIKE BAPI_MATRETURN2 OCCURS 0 WITH HEADER LINE.
XPLANTDATA-PLANT = P_WERKS. " set plant here
XPLANTDATA-DEL_FLAG = 'X'.
APPEND XPLANTDATA.
XPLANTDATAX-PLANT = P_WERKS. " set plant here
XPLANTDATAX-DEL_FLAG = 'X'.
APPEND XPLANTDATAX.
REFRESH XHEADDATA.
XHEADDATA-MATERIAL = P_MATNR. " set material number here
XHEADDATA-STORAGE_VIEW = 'X'.
XHEADDATA-INP_FLD_CHECK = 'W'.
APPEND XHEADDATA.
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
HEADDATA = XHEADDATA
PLANTDATA = XPLANTDATA
PLANTDATAX = XPLANTDATAX
TABLES
RETURNMESSAGES = XRETURN.
IF SY-SUBRC = 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
ENDIF.
‎2009 Aug 04 7:44 AM
Hi Dzed,
Can we delete the material by directly using BAPI_MATERIAL_SAVEDATA by entering all deletion flag fields and all required field? Also by using the above code, will be material be deleted at all level or just plant level?
‎2009 Aug 04 8:08 AM
Hello
No. For delete on client level you need fill only BAPI_MARA-DEL_FLAG.
DATA: XHEADDATA LIKE BAPIMATHEAD OCCURS 0 WITH HEADER LINE,
XCLIENTDATA LIKE BAPI_MARA OCCURS 0 WITH HEADER LINE,
XCLIENTDATAX LIKE BAPI_MARAX OCCURS 0 WITH HEADER LINE,
XRETURN LIKE BAPI_MATRETURN2 OCCURS 0 WITH HEADER LINE.
XCLIENTDATA-DEL_FLAG = 'X'.
APPEND XCLIENTDATA.
XCLIENTDATAX-DEL_FLAG = 'X'.
APPEND XCLIENTDATAX.
REFRESH XHEADDATA.
XHEADDATA-MATERIAL = P_MATNR. " set material number here
XHEADDATA-BASIC_VIEW = 'X'.
XHEADDATA-INP_FLD_CHECK = 'W'.
APPEND XHEADDATA.
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
HEADDATA = XHEADDATA
CLIENTDATA = XCLIENTDATA
CLIENTDATAX = XCLIENTDATAX
TABLES
RETURNMESSAGES = XRETURN.
IF SY-SUBRC = 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
ENDIF.
‎2009 Aug 04 9:42 AM
Hi Dzed,
when I m trying to delete material through this BAPI bu marking the flag for deletion, it is not being flagged for deletion. I can see this material in MM03. Please help me on this.
‎2009 Aug 04 9:54 AM
Hello
Balu Latpate have said you above: Material only mark as deleted.
In MM03 you can see this material, but will be message that this material was deleted on client level.
For delete this material from tables you need to archive this (t-code SARA, object MM_MATNR).
‎2009 Aug 04 10:55 AM
Hi Dzed,
I can not see any message as you mentioned neither while doing it through BAPI nor while viewing in MM03. Please correct me am i going in right direction?
‎2009 Aug 04 11:50 AM