MV45AFZZ Sales Order Save Logic
Understand how MV45AFZZ is used for sales order validation and custom save logic.
Explanation
MV45AFZZ is one of the most common SD user-exit includes. It is used in sales order processing and contains routines such as USEREXIT_SAVE_DOCUMENT_PREPARE and USEREXIT_SAVE_DOCUMENT. USEREXIT_SAVE_DOCUMENT_PREPARE is commonly used for validations before save. Because this exit can be triggered from VA01, VA02, copy control, background jobs and interfaces, logic must be restricted using guard conditions. Avoid broad validations that affect every order type. Also avoid heavy database logic because sales order save is a critical user transaction.
Code example
* Purpose:* Add sales order save validation in MV45AFZZ.* Keep the logic restricted to the intended process only. FORM userexit_save_document_prepare. * Guard condition: * Run only for sales org 1000 and standard order OR. * Without this, the validation can block unrelated orders. IF vbak-vkorg <> '1000' OR vbak-auart <> 'OR'. RETURN. ENDIF. * Validate item-level custom field before save. LOOP AT xvbap ASSIGNING FIELD-SYMBOL(<ls_item>). * Example rule: * License is mandatory for relevant order items. IF <ls_item>-zz_license IS INITIAL. MESSAGE 'License data is required before saving sales order' TYPE 'E'. ENDIF. ENDLOOP. ENDFORM.Real project scenario
A pharma process blocks sales order save when mandatory license data is missing for regulated materials. The validation runs only for selected sales org and order type.
Common mistakes
- Running validation for all order types. - Not testing VA01, VA02 and copy scenarios. - Using SELECT inside item loop. - Changing XVBAP without understanding standard behavior.
Best practices
- Use guard conditions. - Keep save logic lightweight. - Test create/change/copy flows. - Use clear error messages.
Interview angle
Interviewers often ask where to validate before sales order save. MV45AFZZ and USEREXIT_SAVE_DOCUMENT_PREPARE are common answers.