User Exits Part 1: What SD User Exits Are and How They Work
Free sample lesson · open to everyone
Understand classic SD user exits: FORM routines in SAP includes like MV45AFZZ, MV50AFZ1 and RV60AFZZ, why they need a one-time access key, which global data they see, how they differ from customer exits (CMOD), and the basic rules for writing code in them.
In this lessonShow sectionsHide sections
Visual overview
Expert visual walkthrough
What SD User Exits Are and How They Work
User Exits · Chapter-specific technical teaching map
Integration path
SD transaction
Standard include
USEREXIT call
Business update
Tutor's chapter takeaway
Understand classic SD user exits: FORM routines in SAP includes like MV45AFZZ, MV50AFZ1 and RV60AFZZ, why they need a one-time access key, which global data they see, how they differ from customer exits (CMOD), and the basic rules for writing code in them.
In a real project
A company needed a custom "sold-to country" field on the order header, filled automatically from the sold-to party. The team appended ZZCOUNTRY to VBAK, filled it in USEREXIT_MOVE_FIELD_TO_VBAK and added it to the screen via…
Watch out for
• Using VBAP in header-level exits (only the current/last item). • Ignoring UPDKZ = 'D' (deleted items) in XVBAP. • Running checks in display mode. • Writing large logic directly in the SAP include. • Changing fields the exit…
The situation: a real project scenario
A company needed a custom "sold-to country" field on the order header, filled automatically from the sold-to party. The team appended ZZCOUNTRY to VBAK, filled it in USEREXIT_MOVE_FIELD_TO_VBAK and added it to the screen via the customer subscreen.
In the first version, the developer used VBAP in a header exit, where it only contained the last processed item. Switching to XVBAP loops fixed wrong results in multi-item orders — and became the team's first user-exit rule.
Explanation
SD user exits are empty FORM routines, named USEREXIT_…, sitting in SAP includes that SAP has reserved for customer code — MV45AFZZ for sales orders is the best-known example. They run inside SAP's own program and can see all of its global data: VBAK, VBAP, XVBAP, YVBAP, VBKD, XVBPA, and more. Technically, they count as modifications of an SAP include, requiring an access key, but SAP specifically designed them for customer use.
This lesson opens an eight-part series: Part 1 (this lesson) covers what SD user exits are; Part 2 compares user exits, customer exits, and BAdIs, and when to migrate between them; Part 3 covers finding user exits in real transactions; Part 4 covers MV45AFZZ sales order exits; Part 5 covers MV50AFZ1 delivery exits; Part 6 covers RV60AFZZ billing exits; Part 7 covers safe coding rules; and Part 8 covers performance risks.
User exits live in specific includes depending on the transaction: for the sales order (SAPMV45A), that's MV45AFZZ, MV45AFZB, MV45AFZA, and the data-declaration includes MV45ATZZ/MV45ATZ1; for the delivery (SAPMV50A), that's MV50AFZ1 and MV50AFZZ; for billing (SAPLV60A), that's RV60AFZZ and RV60AFZC; and for pricing, that's RV61AFZA/RV61AFZB along with routines in VOFM — copy control and data transfer routines, also configured through VOFM, are related but configured per copy rule rather than being a user exit as such.
They're called from a fixed point in SAP's own program, which contains something like PERFORM userexit_save_document_prepare.; the FORM itself exists as an empty shell in the include, and you add your own code between its FORM and ENDFORM statements.
Changing MV45AFZZ requires an access key from SAP (through SSCR), obtained once per object and system; afterward, your changes are recorded as modifications, though SPAU usually shows no conflict, because SAP itself doesn't change the content of these particular FORMs.
The global data available includes, at the header level, VBAK (the current header) and *VBAK (the old values, in change mode); at the item level, XVBAP (all items, carrying an UPDKZ flag — I for insert, U for update, D for delete), YVBAP (the before-image), and VBAP (the current item, in item-level exits); partner data in XVBPA; business data in VBKD/XVBKD; schedule lines in XVBEP; and the transaction type in T180-TRTYP (H for create, V for change, A for display).
Comparing the technologies: customer exits (SMOD/CMOD) are function modules with clearly defined parameters, so you only ever see what's explicitly passed to them, while user exits see everything in the program's global data — more power, but also more risk, since one wrong assignment to global data can corrupt the whole document, so you should only ever change what the specific exit is meant to change.
To practice, display MV45AFZZ in SE38 and read the comment above each FORM, set a breakpoint in USEREXIT_SAVE_DOCUMENT_PREPARE in a test system and save an order in VA02, and inspect VBAK, XVBAP (and its UPDKZ flags), and T180-TRTYP in the debugger. By the end, you should know what SD user exits are, where they live, and what data they can see.
Code example
* ===== Include MV45AFZZ (sales order) - structure =====*---------------------------------------------------------------------** FORM USEREXIT_SAVE_DOCUMENT_PREPARE **---------------------------------------------------------------------** Called before the document is saved; checks and final changes **---------------------------------------------------------------------*FORM userexit_save_document_prepare.* Guard: only for our order type and not in display mode CHECK t180-trtyp <> 'A'. " T180-TRTYP = A means display mode; nothing is saved, so skip checks IF vbak-auart = 'ZOR'. PERFORM zz_check_po_number. " own FORM in a Z include (see below) ENDIF.ENDFORM. *---------------------------------------------------------------------** FORM USEREXIT_MOVE_FIELD_TO_VBAK **---------------------------------------------------------------------** Fill header fields (incl. append fields ZZ...) during entry **---------------------------------------------------------------------*FORM userexit_move_field_to_vbak. IF vbak-zzcountry IS INITIAL. vbak-zzcountry = kuagv-land1. " copy sold-to country into custom append field ENDIF.ENDFORM. * ===== Own logic kept in a customer include (e.g. ZMV45AFZZ_CHECKS) =====FORM zz_check_po_number. DATA ls_item TYPE vbapvb. IF vbak-bstnk IS INITIAL. MESSAGE e001(zsd). " 'PO number required for ZOR' ENDIF.* Example: loop over all items that are not deleted LOOP AT xvbap INTO ls_item WHERE updkz <> 'D'. " UPDKZ = D marks an item the user deleted on screen " item-level checks here ENDLOOP.ENDFORM. * ===== Useful global data =====* VBAK / *VBAK header, old header (change mode)* XVBAP / YVBAP items new / old, UPDKZ = I, U, D* XVBPA partners XVBKD business data XVBEP schedule lines* T180-TRTYP H = create, V = change, A = displayWatch out
Common mistakes
- Using VBAP in header-level exits (only the current/last item).
- Ignoring UPDKZ = 'D' (deleted items) in XVBAP.
- Running checks in display mode.
- Writing large logic directly in the SAP include.
- Changing fields the exit is not intended for.
Do this
Best practices
- Read the SAP comment above each FORM.
- Keep FORMs thin; put logic in Z includes or classes.
- Guard by document type and transaction type.
- Use X/Y tables correctly and respect UPDKZ.
- Document every exit use in a register.
In the interview
Interview angle
Questions: "What is a user exit?", "Name SD user exit includes.", "Difference between user exit and customer exit?"
Strong answer: FORM routines in SAP includes reserved for customers (MV45AFZZ, MV50AFZ1, RV60AFZZ), called via PERFORM; need an access key once; see all global data (VBAK, XVBAP/YVBAP with UPDKZ, XVBPA, T180-TRTYP); customer exits are function modules with parameters activated via CMOD; user exits are powerful but risky.
Practice this lesson
Quick check
0 of 3 questions attempted
Question 1 of 3
In a header-level sales order exit, which table contains ALL items of the document?
Question 2 of 3
User exits live in:
Question 3 of 3
Which include is commonly used for sales order user exits?
Practise this in an interview
Answer in your own words and get instant feedback, the way an interviewer would judge it.
1Are user exits considered modifications?
2A header-level check in a sales order user exit read VBAP and gave wrong results for orders with several items. Why, and what should it use?
Try a related Code Lab
This published exercise covers the same SAP topic. Apply the ideas in a hands-on scenario, then return to review your answers.
Open: Moving User Exit Logic to Service Class →See it in code
Each example starts from a requirement, shows the design, then the code step by step with a plain-language explanation of every part.
Was this lesson helpful?
Keep exploring
Interview questions on this topic
Related SAP topics
Referenced SAP objects
Reviewed reference pages for the objects this page mentions.
Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.