Download Business Object Attachments (e.g. from a purchase order)
Please also have a look in our OnlineHelp for further information.
From SAP rel. 4.6 the user can attach documents to all common business objects. The image shows how to attach a drawing to a purchase order.
The function modules BDS_CONNECTIONS_GET and BDS_DOCUMENT_GET_TABLE can’t be used here. Even if BDS_CONNECTIONS_GET delivers correct document IDs the function BDS_DOCUMENT_GET_TABLE throws a NOTHING_FOUND exception.
So we have to discuss a different way to query attachments of a business object. The following code shows how to read the table SRGBTBREL to obtain all document IDs attached to a business object. The object key is the document number (e.g. the purchase number) the object type is the name of the business object (e,.g. BUS2012 for POs or BUS2010 for RFQs). The function returns an array of strings each representing a key to a downloadable attachment.
To find out some more details on each attachment we have to take a look into table SOOD. The primary key of the table entry is defined by certain parts of the document IDs provided by the function above. The file name of the attachment can be created by concatenating OBJDES and FILE_EXT.
To download an attachment by a given object ID we use SO_DOCUMENT_READ_API1. The returning structure DOCUMENT_DATA contains some information about the file (e.g. DOC_SIZE). The table OBJECT_CONTENT returns the binary content of the attachment as a string (don’t ask why). The strings are converted into byte arrays and stored to disk.
This sample program uses the three functions discussed earlier to download all attachments to a given purchase order number. To download attachments of other business objects, just change the object type (e.g. BUS2010 for RFQ).