If the requirement is to send the PDF files fetched from the attachment list of service notifications once the service order reaches to specific status, how to get those linked document files based on the service order number will be the key. That is the purpose of this article.
call function 'BAPI_DOCUMENT_GETDETAIL2'
exporting
documenttype = drad-dokar
documentnumber = drad-doknr
documentpart = drad-doktl
documentversion = drad-dokvr
getobjectlinks = 'X'
getcomponents = 'X'
getactivefiles = 'X'
getdocdescriptions = 'X'
getdocfiles = 'X'
getclassification = 'X'
importing
documentdata = l_documentdata
return = l_return
tables
objectlinks = lt_objectlinks
documentdescriptions = lt_documentdescriptions
longtexts = lt_longtexts
statuslog = lt_statuslog
documentfiles = lt_documentfiles "<===store the attachment files
components = lt_components
characteristicvalues = lt_characteristicvalues
classallocations = lt_classallocations
documentstructure = lt_bapi_doc_structure
whereusedlist = lt_whereusedlist.
ls_object_id-class = 'DMS_PCD1'.
ls_object_id-objid = wa_document_file_id-file_id.
call function 'SDOK_PHIO_LOAD_CONTENT'
exporting
object_id = ls_object_id
client = sy-mandt
tables
file_access_info = l_file_access_info
file_content_binary = l_file_content_binary
exceptions
not_existing = 1
not_authorized = 2
no_content = 3
bad_storage_type = 4
others = 5.
call function 'SCMS_BINARY_TO_XSTRING'
exporting
input_length = l_file_detail-file_size
first_line = l_file_detail-first_line
last_line = l_file_detail-last_line
importing
buffer = r_file_in_binary
tables
binary_tab = l_file_content_binary
exceptions
error_message = 1
others = 2.
gt_attach_content = cl_document_bcs=>xstring_to_solix( gv_pdf_xstring ).
gv_attach_size = xstrlen( gv_pdf_xstring ).
CL_DOCUMENT_BCS->add_attachment( i_attachment_type = lv_file_type
i_attachment_subject = lv_file_subject
i_attachment_size = gv_attach_size
i_att_content_hex = gt_attach_content
).
Please kindly comment if any quick approach can fetch those attachment files more efficiently and more straightforwardly. Thanks : )