Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Jigang_Zhang张吉刚
Active Contributor
0 Kudos
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.



1, Get the notification number(QMNUM) from AFIH (Maintenance order header) based on the Service order number(AUFNR).




2, Get Document Type(DRAD-DOKAR) and Document number(DRAD-DOKNR) from DRAD(Document-Object Link) with the notification number used as OBJKY.




3, Fetch the attachment lists through BAPI_DOCUMENT_GETDETAIL2 from the Service notification based on document details.

  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.

4. Filter those file attributes like file name/extension/creation time etc inside lt_documentfiles.



5, Load the Content of the Physical document Object into an Internal Table through 'SDOK_PHIO_LOAD_CONTENT' according to lt_documentfiles-file_id.

  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.

6, Convert the files' Binary content into XSTRING with 'SCMS_BINARY_TO_XSTRING'.

    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.

7. Finally, convert Xstring to Solix with cl_document_bcs=>xstring_to_solix and send an email with BCS.

    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 : )