You find relation between material master and document master in table DRAD.
select * from DRAD
where dokob = 'MARA'
and 'OBJKY' = matnr.
Use BAPI BAPI_DOCUMENT_GETDETAIL2 to get details of the document master. Table DOCUMENTFILES contains all files connected to the document master. Fields APPLICATION_ID and FILE_ID of table DOCUMENTFILES contain LOIO and PHIO.