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
US_EXIT = CHARX.
That’s it – This way items cannot be deleted from sales documents.