I need some guidance on how to run my custom function module whenever a user posts an invoice through FB60 or MIRO transactions. I attempted to trace the events to understand the process flow, but I couldn’t find any default function modules being triggered during the posting process. This makes it difficult for me to identify the exact event that I should hook into. Has anyone successfully implemented something similar? What would be the best approach to automatically execute my custom logic during invoice posting? I’m looking for a reliable method that will consistently trigger my function module every time an invoice gets posted in the system.
User exits are your best bet. Check USEREXIT_SAVE_DOCUMENT_PREPARE in include MV50AFZ1, or try enhancement spots like INVOICE_UPDATE. I’ve used the BADI FI_AUTHORITY_ITEM for similar stuff where I needed custom code during document posting - worked great. Just find the right enhancement point that fires consistently for both transactions. You could also use workflow events since FB60 and MIRO both trigger standard SAP events during posting that you can subscribe to. I’ve also implemented a custom BADI in the ACC_DOCUMENT enhancement spot - it gets called during financial document creation. Test everything thoroughly in dev though, since these enhancements can tank performance if you mess them up.