User Exits Part 7: Safe Coding Rules Inside User Exits
Preview · a free account unlocks the full lesson
Protect standard processes when coding in user exits: guard conditions, transaction type and processing mode checks, correct message types, no COMMIT/ROLLBACK/CALL TRANSACTION, no popups in background, careful handling of global data, namespaces for own variables and code organisation in Z includes.
In this lessonShow sectionsHide sections
Visual overview
Explanation
Parts 4 through 6 of this series showed what to do inside specific exits; this lesson is the general rule set that applies to any exit.
Every exit should start with guard conditions, for example CHECK vbak-auart = 'ZOR'. or an IF … RETURN, and CHECK t180-trtyp <> 'A'. to keep logic out of display mode. Check the call context when it matters, too: sy-tcode is unreliable for BAPIs, so use call_bapi/call_activity flags where the program provides them, or check sy-batch instead.
Transactional safety matters because SAP commits the document itself. Any of your own database writes should go through update function modules called IN UPDATE TASK, or through PERFORM … ON COMMIT — never through CALL TRANSACTION, a BAPI that commits, or an RFC with an implicit commit placed inside save exits.
On messages: an E message in a checking exit (such as SAVE_DOCUMENT_PREPARE) stops the save, and a BAPI returns it as an error; W or I messages should only be used when the process can actually handle them, and should be avoided in background processing; A and X messages should never be used in exits; and POPUP_TO_CONFIRM should never appear when sy-batch = 'X' or inside BAPI calls.
Create a free account to keep reading
You have read the opening of this lesson. A free ERPClimb account unlocks the rest of it, every other lesson and topic, and your learning history, so you can pick up exactly where you stopped. No card needed.
- Full explanation
- Code example
- Real project scenario
- Common mistakes
- Best practices
- Interview angle
One tap with Google works too. Every topic keeps its first lesson open to everyone.
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.