Hi,
Janis & Jozef have already highlighted the pitfalls of this design.
My suggestion is - After calling the transaction 'MIRO' it should come back to the calling program with messages for a single IR document. This can be done by using -CALL TRANSACTION using bdcdata messages into msg . This holds good, if the documents are processed in a loop.
Or use a BAPI serving the same purpose and then check the return parameters.
Advantages - You can collect all the created/changed invoices and then update Z table at one shot.
Or use some exit in the MIRO to populate the ZTABLE. ( As suggested by Janis/ Jozef )
Regards,
DPM