User Exits Part 5: MV50AFZ1 — Delivery User Exit Patterns
Apply delivery user exits in MV50AFZ1: USEREXIT SAVE DOCUMENT PREPARE for checks and changes with LIKP and XLIPS, USEREXIT SAVE DOCUMENT for own tables, batch split items, background delivery creation (VL10) and when the BAdI LE SHP DELIVERY PROC is the better choice.
Explanation
📌 KEY POINTS
✅ MV50AFZ1 contains the delivery exits of SAPMV50A: USEREXIT_SAVE_DOCUMENT_PREPARE and USEREXIT_SAVE_DOCUMENT are the most used.
✅ Data: LIKP (header), XLIPS/YLIPS (items new/old with UPDKZ), XVBPA (partners), XVBFA (document flow).
✅ Deliveries are often created in background (VL10 collective processing) and via IDocs — exits must not rely on dialog.
⚠️ For many delivery requirements, SAP's classic BAdI LE_SHP_DELIVERY_PROC offers cleaner methods — check it first.
━━━━━━━━━━━━━━━━━━━━
▶ WHERE WE ARE
Part 4 covered sales orders. Deliveries follow the same pattern with different tables and more background processing.
━━━━━━━━━━━━━━━━━━━━
▶ 1. KEY FORMS
- USEREXIT_SAVE_DOCUMENT_PREPARE — checks and final changes before save (e.g. block delivery, set a Z field, validate batches).
- USEREXIT_SAVE_DOCUMENT — during save; write own tables via update task.
- USEREXIT_MOVE_FIELD_TO_LIKP / _LIPS — fill header/item fields during creation (these FORMs are in MV50AFZ1 / related includes depending on release).
━━━━━━━━━━━━━━━━━━━━
▶ 2. ITEMS AND BATCH SPLIT
- XLIPS contains main items and batch split sub-items (UECHA = higher-level item).
- For quantity checks use the main item or sum the split items — not both.
- Skip deleted items (UPDKZ = 'D').
━━━━━━━━━━━━━━━━━━━━
▶ 3. BACKGROUND AND INTERFACES
- VL10 creates many deliveries in one run; the exit runs per delivery.
- An error message in SAVE_DOCUMENT_PREPARE prevents that delivery from being created and appears in the collective processing log.
- No popups; buffer lookups (Part 8).\n\n━━━━━━━━━━━━━━━━━━━━\n▶ 4. LE_SHP_DELIVERY_PROC (CLASSIC BADI)\nMethods such as CHANGE_DELIVERY_HEADER, CHANGE_DELIVERY_ITEM, SAVE_DOCUMENT_PREPARE, SAVE_AND_PUBLISH_DOCUMENT and CHECK_ITEM_DELETION give parameter-based access. Prefer it for new requirements where it offers the needed point.
━━━━━━━━━━━━━━━━━━━━
▶ 5. TYPICAL REQUIREMENTS
- Block deliveries for customers with a Z flag (set LIKP-LIFSK or raise error).
- Fill a Z field in LIKP from the sales order (via XVBFA/VBAK read).
- Validate that batches are assigned before PGI (better: incompletion/checks in customizing where possible).
━━━━━━━━━━━━━━━━━━━━
▶ STEP BY STEP
- SE38: display MV50AFZ1 and read the FORM comments.
- Debug VL02N save; inspect LIKP, XLIPS (with batch split) and UPDKZ.
- Implement the batch check from the code example in a sandbox and test via VL10.
✅ CHECKPOINT: you can implement delivery checks that work online, in VL10 and for IDocs.
Code example
* ===== MV50AFZ1 =====FORM userexit_save_document_prepare. DATA: ls_lips TYPE lipsvb, lv_error TYPE abap_bool. * Guard: only outbound deliveries of our type CHECK likp-lfart = 'ZLF'. * ----- Check: every batch-managed main item needs a batch (or split) ----- LOOP AT xlips INTO ls_lips WHERE updkz <> 'D' AND uecha IS INITIAL. " main items only IF ls_lips-xchpf = 'X' AND ls_lips-charg IS INITIAL.* Batch split items carry the batch; check whether sub-items exist READ TABLE xlips TRANSPORTING NO FIELDS WITH KEY uecha = ls_lips-posnr. IF sy-subrc <> 0. lv_error = abap_true. EXIT. ENDIF. ENDIF. ENDLOOP. IF lv_error = abap_true. MESSAGE e020(zle) WITH ls_lips-posnr. " in VL10 this appears in the log ENDIF.ENDFORM. FORM userexit_save_document.* Own table entry written together with the delivery DATA ls_log TYPE zdlv_log. ls_log-vbeln = likp-vbeln. ls_log-ernam = sy-uname. CALL FUNCTION 'Z_DLV_LOG_SAVE' IN UPDATE TASK EXPORTING is_log = ls_log.ENDFORM. * ===== Alternative: classic BAdI LE_SHP_DELIVERY_PROC =====* METHOD if_ex_le_shp_delivery_proc~save_document_prepare.* " parameter-based access to delivery tables (see SE18 for exact parameters)* ENDMETHOD.Real project scenario
A batch check in the delivery exit rejected valid deliveries in VL10 runs. The code checked all XLIPS entries, including batch split sub-items whose main item had no batch by design.
Restricting the check to main items (UECHA initial) and looking for sub-items fixed it. The collective processing log now showed only real errors, and the warehouse stopped bypassing the check manually.
Common mistakes
- Treating batch split sub-items as separate items.
- Popups or dialog-only logic in delivery exits.
- Ignoring deleted items.
- Changing LIKP/XLIPS in SAVE_DOCUMENT (too late).
- Not considering LE_SHP_DELIVERY_PROC for new logic.
Best practices
- Guard by delivery type.
- Handle main items and split items deliberately.
- Test online, VL10 and IDoc creation.
- Own tables via update task.
- Prefer LE_SHP_DELIVERY_PROC where suitable.
Interview angle
Questions: "Which user exit do you use for delivery checks?", "What are XLIPS and UECHA?", "LE_SHP_DELIVERY_PROC?"
Strong answer: MV50AFZ1 USEREXIT_SAVE_DOCUMENT_PREPARE for checks/changes with LIKP and XLIPS/YLIPS (UPDKZ), SAVE_DOCUMENT for own tables via update task; batch split items have UECHA; exits run in VL10/IDoc without dialog; classic BAdI LE_SHP_DELIVERY_PROC offers parameter-based methods and is often preferable.
Practice this lesson
Quick check
1. Which classic BAdI often offers a cleaner alternative to delivery user exits?
2. In XLIPS, how are batch split sub-items identified?
3. Which include is commonly used for delivery user exits?
Interview questions
1. A delivery save validation works in VL02N but fails during background delivery processing. What would you check?
Answer it in your own words first, then compare.
2. A batch validation was meant for LF deliveries only but was applied to all delivery types, including returns. How do you correct the MV50AFZ1 logic?
Answer it in your own words first, then compare.
Reference-verified: the steps are checked against official SAP documentation and tutorials, and object and field names in the sample code are checked for consistency. The code has not been compiled or run on an SAP system by ERPClimb. Syntax marked release-dependent varies by SAP release, so check it in your own system.
More lessons in this topic
- User Exits Part 1: What SD User Exits Are and How They Work
- User Exits Part 2: User Exits vs Customer Exits vs BAdIs — When to Migrate
- User Exits Part 3: Finding User Exits in Real Transactions
- User Exits Part 4: MV45AFZZ — Sales Order Exits and Save Logic
- User Exits Part 6: RV60AFZZ — Billing User Exit Patterns
- User Exits Part 7: Safe Coding Rules Inside User Exits
- User Exits Part 8: Performance Risks in User Exits