cancel
Showing results for 
Search instead for 
Did you mean: 

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.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'EXPORTING
input_length = ls_act-comp_size
FIRST_LINE = 1
LAST_LINE = 9IMPORTINGBUFFER = fi_xstringtables
binary_tab = lt_bin[]* EXCEPTIONS* FAILED = 1* OTHERS = 2.IF sy-subrc <> 0.* Implement suitable error handling hereENDIF.

cl_bcs_convert=>xstring_to_string(EXPORTING
iv_xstr = fi_xstring
iv_cp = '1160'
RECEIVING
rv_string = fi_string ).

cl_bcs_convert=>string_to_solix(EXPORTING
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 ).

Jelena
Active Contributor

I've never had to deal with the Word files in SAP (thankfully), much less with the embedded images in them. But since there have been no other replies - you could try to narrow down the problem. E.g. does it work if you don't specify the codepage? Does it work fine if there is no image? What if you just read data from the file instead of getting data from FM?

In general, I find that the less manipulation the better. The program I used for Excel and PDF that reads a file from the app server and emails it out simply uses OPEN DATASET... BINARY, then cl_document_bcs=>xstring_to_solix and off it goes into the email attachment with the RAW type.

0 Kudos

Thanks, Jelena. Unfortunately, the files are in DMS and not in AL11. And the manipulations seem necessary. Due to how the config is, the entries for files are not going in DRAW table and SCMS_DOC_READ is the only way I am able to read file data which is in RAW 1022. So in order to convert it to solix, I have to do a lot of dancing.

The better methods for conversion require codepage. I have tried with many codepages. Without images it works but only for very basic WORD, Excel etc. For heavy files with loads of tables, data, and other Word/Excel features at play, the file straight up gets corrupted. I am at my wit's end as I have gone through all possible SCN docs and notes it seems.

Best Regards,

Soumyajit

Accepted Solutions (0)

Answers (1)

Answers (1)

0 Kudos

Hello,

We have resolved the problem by borrowing some code from PPM FPM portal code. Will share the detailed solution soon in case someones else gets stuck with same problem.

Best Regards,

Soumyajit

keohanster
Active Contributor

Hi Soumyajit,

That would be excellent to circle back and share your solution! And please close the question too, of course.


Thanks,

Sue