Skip to Content

How to prevent deletion of sales order items

Business requirement: In some cases, a sales order item should never be able to be deleted.

Business scenario: In a multi-plant SAP landscape; for only one plant, production is handled in a separate system (PSI) integrated to SAP ERP. Production requests to PSI are sent from SAP as sales order items, so in this case, any sales order item should not be deleted. Sales order cancellation should be done only by setting a reason for rejection.

Reason for development: Preventing deletion of sales order items via customizing is not possible. Authorization object V_VBAK_AAT is relevant on order header level, and the choice for maintaining sales documents via SHD0/screen variants was not accepted by customer.

Two possible solutions exist. Both of them are enhancements.

Solution 1: Enhancement in program MV45AFZZ, form USEREXIT_SAVE_DOCUMENT_PREPARE.

This form is called on save event, after item is deleted. You can force an error message, but user will be forced to exit from the document, and any other change made will be gone. A better approach might be found, which will be briefly explained in Solution 2.

Solution 2: Enhancement in program MV45AFZB, form USEREXIT_CHECK_XVBAP_FOR_DELET.

This form is called when user tries to delete an item from the sales document or by clicking Delete button and confirming the popup or tries to delete the order from the header by selecting Sales document -> Delete. This way, user will be informed immediately that item cannot be deleted. Required code is as below:

IF… “Appropriate condition to separate deletable items for other plants

IF VBAP-POSNR NE ‘000000’. “This prevents a short dump when user tries to delete the order from the header by selecting Sales document -> Delete

          MESSAGE E028(ZPSI).


        US_EXIT = CHARX.


That’s it – This way items cannot be deleted from sales documents.

You must be Logged on to comment or reply to a post.
  • Nice Document and thanks for sharing the same !

    Just to add, there is an User exit available to disable the delete option for Sales Order schedule lines : USEREXIT_CHECK_XVBEP_FOR_DELET.



    • Hi Arindam,

      Thank you for your input, appreciated.

      I remember trying to use that form but had decided not to. I wondered why and checked again.

      In form USEREXIT_CHECK_XVBEP_FOR_DELET, if you change the vbap values to vbep in the code mentioned;

      * When you try to delete the item by Delete item button, it works perfectly fine.

      * When you try to delete the complete order by Sales document -> Delete functionality, it will give you a short dump.

      I guess that's why I decided for xvbap.

  • Kivanc,

    The business scenario you have sited will help in our knowledge building.

    To understand this -

    One plant outside SAP is the manufacturing plant. The other plants are the delivering plants and are setup in SAP. The demand from delivering plant is sent to the manufacturing plant.

    Why putting reason for rejection would be ok instead of deleting the line items in the SAP order?



    • Hi Typewriter,

      Actually in scope all plants are manufacturing plants. A new plant is opened, but due to complexity of LO-VC processing, customer decided to manage Production Processes of this plant outside of SAP (PSI system).

      To open doors of perception from your side: Sales order items are sent from SAP to PSI via IDOCs and PSI is sending information back to SAP via a different IDOC as well. So if you ever delete an item from SAP directly, the link between SAP and PSI will be broken. That's why we were not to let this happen.

      • Kivanc,

        Thanks for sharing this real time experience!

        If user puts a reason for rejection, then does this RoR information go to PSI?


          • Kivanc,

            So there is a message from SAP to PSI when order is created and a message when a change is done for example RoR is set for an item in the order.

            You mentioned PSI sends information back to SAP, what does this message contain? is it a confirmation?


          • Basically yes, it's a confirmation message, though the complete integration is a bit more complex than I've summarized. I did not want to get in more detail in the document, as it would be a tad irrelevant for the actual requirement, but I know you like talking about real-time experiences so I'll get into more detail here. There is actually another system as well in this project scope; an advanced planning and allocation system named Quintiq (a la SAP APO, seemingly stronger than SAP APO), and there are more IDOCs both sent and received as well. Sending of idocs are triggered on sales order item status changes, and all three systems are integrated within the other two and talk to eachother. Talk about integration capabilities of SAP, eh? 🙂

  • this worked perfectly but when deleting the whole order is deemed OK (that is when vbap-posnr = '000000') I put the US_EXIT assignment in the inner IF statement not the outer.