Execute custom FM when posting invoices in FB60 or MIRO

I need help with running my custom function module automatically when users post invoices through FB60 or MIRO transactions.

I have been trying to figure out how to make this work but I am stuck. When I tried to trace the events to see what happens during invoice posting, I could not find any existing function modules that get triggered by default.

Since there are no standard FMs being called during the posting process, I cannot identify which events I should be hooking into. This makes it really difficult to determine where exactly I should place my custom logic.

Has anyone successfully implemented something similar? What approach did you use to automatically execute custom code during invoice posting in these transactions? Any guidance on the right events or enhancement spots would be really helpful.

bapi enhancement could work. try bapi_incominginvoice_create and similar ones - they’ve got enhancement spots you can hook into. also check substitution/validation rules in ob28, sometimes that’s easier than custom exits. workflow events are another option if timing isn’t critical.

User exits are a solid approach for your requirements. In SPRO, navigate to the vendor invoice processing area to find several user exits specifically for MIRO and FB60. One that has worked well for me is EXIT_SAPLMR1M_001 for MIRO, as it activates prior to the document posting. For FB60, you might want to explore the FI user exits, such as RFAVIS01. Alternatively, consider using BAdIs, which can be accessed via SE18; they offer a more robust solution compared to user exits. If you need to act post-posting, change documents could also serve your needs. It’s essential to clarify whether your custom code should execute before, during, or after the posting process.

I’d look at the enhancement framework first. Fire up SE80 and search for enhancement spots in MRMA (MIRO) and RFBP (FB60). There are several implicit enhancement points in the standard posting routines you can activate without touching core code. Use SE19 to implement them cleanly. You could also try posting control tables - set up automatic account assignment with substitution rules that’ll trigger your FM indirectly. Figure out if you need pre-posting validation or post-posting processing first, since that determines which enhancement point works. Document change callbacks like ADDR_CHANGE or similar table events can trigger custom logic pretty reliably too.