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

BAPI for material deletion

Former Member
0 Likes
6,456

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,798

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.

13 REPLIES 13
Read only

Former Member
0 Likes
3,798

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.

Read only

GauthamV
Active Contributor
0 Likes
3,798

Use this bapi.

BAPI_MATERIAL_DELETE

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
3,798

link:[http://abap.wikiprog.com/wiki/BAPI_MATERIAL_MAINTAINDATA_RT]

Read only

Former Member
0 Likes
3,798

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.

Read only

Former Member
0 Likes
3,798

Hi Dzed,

Can you please tell me that how we can use BAPI_MATERIAL_SAVEDATA to delete the material?

Read only

0 Likes
3,798

check documentation if available

Read only

0 Likes
3,798

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.

Read only

Former Member
0 Likes
3,798

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?

Read only

0 Likes
3,798

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.

Read only

Former Member
0 Likes
3,799

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.

Read only

0 Likes
3,798

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).

Read only

Former Member
0 Likes
3,798

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?

Read only

Former Member
0 Likes
3,798

Thanx Dzed.