Skip to Content
Oct 08, 2019 at 08:00 PM

Sending PPM attachment via email, DOCX image corrupted


Hello Experts,

I am building an offline approval solution via workflow for PPM checklist items for my client. For each approval request mail is being shot via cl_bcs class to user's email inbox. One of the requirements is to attach all the uploaded files to a particular PPM decision point for the user the refer to.

After lots of research, I am able to get the file content using SCMS_DOC_READ by accessing the physical ID of the files. Data is returned in a raw 1022 binary table. after further headache, I converted the binary content to XSTRING using SCMS_BINARY_TO_XSTRING and then XSTRING to STRING and then STRING to SOLIX for XLSX with codepage 4103. XLSX attachments seem to be working fine.

For DOCX I used same technique but codepage 1100/1160. The file comes fine but the image inside is corrupted. Interestingly, only part of the image is corrupted. This tells me there is some conversion error or data loss at some point. If someone can help out with this or point me in the right direction, I would be eternally indebted.

Below is a code snippet:

IF file2 EQ 'DOC'.DESCRIBE TABLE lt_bin LINES lv_lines.
input_length = ls_act-comp_size
LAST_LINE = 9IMPORTINGBUFFER = fi_xstringtables
binary_tab = lt_bin[]* EXCEPTIONS* FAILED = 1* OTHERS = 2.IF sy-subrc <> 0.* Implement suitable error handling hereENDIF.

iv_xstr = fi_xstring
iv_cp = '1160'
rv_string = fi_string ).

iv_string = fi_string
iv_codepage = '1160'IMPORTING
et_solix = lt_xls_out
ev_size = size ).
CONCATENATE file1 '.docx' INTO lv_file.CONCATENATE '&SO_FILENAME=' lv_file INTO att_line.APPEND att_line to att_head.

document->add_attachment(EXPORTING i_attachment_type = 'TXT'
i_attachment_subject = lv_sub
i_attachment_size = size
i_att_content_hex = lt_xls_out
i_attachment_header = att_head ).