Well, the attachment functionality in QM02 (as in many other places in SAP) is part of Generic Object Services (GOS) and the particular call to make an attachment is a method START_SERVICE_DIRECT in class CL_GOS_MANAGER
For more detailed information on how this method is called to create an attachment refer to this excellent documentation by Manuel Bassani (in page 9). He describes creating GOS for Custom programs, however the documentation is quite detailed and lays down the bare bone details of how the attachments are created, viewed and changed programmatically.
How to Attach Documents to Any Custom Program Using Generic Object Services