Look about GOS concept and if your process uses it, then try to use class CL_GOS_ATTACHMENT_QUERY method COUNT_FOR_OBJECTS .Please, let me know if this information helped you.
I have never tried to insert a CUSTOM BUTTON in ME51N, but, try to see in SMOD the enhancement MEREQ001 .There, there is a SCREEN-EXIT. Maybe can help in your intend to change ME51N. Let me know if you figured out any solution for your case.
Post_document is a update module, so it works in a different workprocess. How they work in different workprocess, the memory area also is different.When you are working in different workprocess, you need to use EXPORT ... TO DATABASE / IMPORT ...FROM...
I´m not sure if i have understood.But, did you try use BADI MB_MIGO_ITEM_BADI ?Maybe in method item_modify you can identify the process´s origin using sy-tcode or field-symbol and then do your requirement.