I need help with calling my custom function module automatically when users post invoices through FB60 or MIRO transactions.
I have been working on this for a while and tried using event tracing to figure out how to hook into the posting process. The problem is that when I trace the events, there are no function modules created by default in the system. This makes it really hard for me to understand which events I should be listening to.
Has anyone successfully implemented something similar? I want my custom logic to run every time an invoice gets posted. What would be the best approach to achieve this? Should I be looking at user exits, BADIs, or some other enhancement technique?
Any guidance on the specific enhancement points or events that fire during invoice posting would be really helpful. Thanks in advance for your assistance.
I encountered a similar situation several months ago and decided to move away from user exits entirely. Instead, I found that using BADIs provided a more streamlined approach for hooking into invoice posting. For FB60, consider utilizing the BADI AC_DOCUMENT with the method CHANGE_AT_SAVE; it activates during the save process, allowing complete access to the accounting document. As for MIRO, the scenario is a bit more complex, given its dual handling of material and accounting documents. Here, BADI MRM_WORKFLOW_AGENTS_DET is beneficial as it activates after the verification posting is complete. I would recommend using BADIs instead of enhancement spots for better upgrade stability, which helps keep custom code distinct from standard SAP functions. Additionally, I discovered that subscription table SWETYPV can aid in identifying business object events if you’re inclined towards event-driven processing rather than direct hooks. Ensure to conduct thorough testing in a sandbox environment, as invoice posting processes involve multiple database updates—buggy custom code can jeopardize the entire posting cycle. Also, the assignment of document numbers occurs late in the process, so if your custom function relies on the final invoice number, plan accordingly.
debugging invoice posting is real tricky, but what works for me is checking BTE events in SE80. BTE 00001030 for FB60 and 00001520 for MIRO are the ones you need. it’s way cleaner than using exits since ur not touching the standard code. just build ur function module and register it in FIBF.
Enhancement spots are definitely your best bet here. I built something similar last year and user exits worked way better than trying to trace events directly. For FB60, check out enhancement point INVOICE_UPDATE in include MV50AFZ1. It triggers right after document posting but before the final commit. For MIRO, go with enhancement MRMH0001 - it’s got multiple exit points during posting. I used the EXIT_SAPLMR1M_010 function in MRMH0001 for MIRO transactions. This exit fires after all validations finish but before actual posting happens. You’ll get access to the invoice document structure and can run your custom logic there. The tricky part? Don’t let your custom code mess with the standard posting logic. I learned this the hard way when my first attempt killed performance. Handle exceptions properly and avoid any database commits in your custom function module - let SAP manage the transactions. Also, if you need post-processing instead of real-time execution, check table T80D for workflow events.