Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

GOS - Cannot open .docx/.xlsx file programmatically attached to business object

h_frye
Explorer
0 Kudos

I am supporting an existing web dynpro application that allows users to attach files to a purchase requsition in SAP.  The current solution allows for a successful attachment and display of .doc and .xls files, but gives an error when displaying .docx and .xlsx files.

The current solution follows this logic:  The code identifies the MIME type of the file to derive the file extension.  Then, it converts the document contents from a xstring type to binary via function SCMS_EXTRING_TO_BINARY.  After the conversion, it creates an initial instance of BO 'MESSAGE' and populates the message container with the required parameters.  It creates the container, refreshes the message object, and gets the key of the new message object.  Then, the code populates the BO object_a and object_b and calls the method   cl_binary_relation=>create_link to attach the file.  Lastly, a commit work statement is executed.  Based on the code samples I have seen online, this solution is logically correct.

I am able to successfully attach .doc and .xls files from this web dynpro application, and then later open them from ME53N.  I am also able to "successfully" attach .docx and .xlsx files from the application.  If I view the attachment list in ME53N, these files are visible.  However, when I attempt to open the attachments, Word/Excel gives me an error message "The file cannot be opened because there are problems with the contents.  The file is corrupt and cannot be opened."  If I click OK to bypass the error, it gives an additional prompt "Word found unreadable content in document.  Do you want to recover the contents of this document?  If you trust the source of this document, click yes."  If I click yes, the document opens.

  • .docx / .xlsx files attached via ME52N will open without issue
  • .doc / .xls files attached programmatically via this web application open without issue
  • these are the MIME types associated with .docx / .xlsx both in the web application and in SAP configuration:
    • .docx:   application/vnd.openxmlformats-officedocument.wordprocessingml.document
    • .xlsx:    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

Does anyone have an idea why the newer document versions appear to be corrupt when opening?  Does the error from Word imply there is a data conversion issue, even though the .doc and .xls documents are readable?  Are the .docx/.xlsx file types unusable with the   cl_binary_relation=>create_link method, and should instead be used with the function 'BINARY_RELATION_CREATE'?

Any help is greatly appreicated.  Thanks in advance!

1 ACCEPTED SOLUTION

h_frye
Explorer

I resolved this issue myself.  It was a simple case of a typo.  When populating the message container with the required parameters, the previous support analyst was passing the wrong variable to the file size parameter.  So essentially the file size was being passed as 0.  Thanks.

4 REPLIES 4

h_frye
Explorer

I resolved this issue myself.  It was a simple case of a typo.  When populating the message container with the required parameters, the previous support analyst was passing the wrong variable to the file size parameter.  So essentially the file size was being passed as 0.  Thanks.

0 Kudos

I replied too quickly.  This change in providing the file size DID help when I was attaching .docx files. They open succesfully now, as well as, .doc and .xls files.

However, I'm still having the same issue when I try attaching .xlsx files.  Furthermore, now .txt files do not display correctly.  Before passing the file size correctly, they were displaying in notepad.  Now, they open in the SAP GUI and only show characters, rather then the actual text.

It seems like this file size typo was just a coincidence for .docx files.  I'm still looking for help on this issue.  Thanks in advance.

0 Kudos

I had a similar problem too and after passing the file size parameter with the correct value, I was able to successfully read both *.docx and *.xlsx files in GUI after attaching them programmatically.

marta_delasota27
Explorer
0 Kudos

Hi.

I have a similar problem but I can open .pdf and .docx files but I can't open .xls and .xlsx files. I used 'SO_DOCUMENT_INSERT' fuction module and 'BINARY_RELATION_CREATE_COMMIT'. Could someone help me?

Thanks a lot.

Marta