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: 

DOCX content error when downloading from AL11 to local PC

matias_z
Participant
0 Kudos

Hi All,

I’m saving a .DOCX file into a SAP Directory (application server, t-code AL11) using the OPEN DATASET FOR OUTPUT IN BINARY MODE, TRANSFER and CLOSE DATASET sentences.

When I download that file stored in AL11 using the t-code CG3Y to my local PC and then try to open that file (from my PC) an error pops up before opening it (it opens anyway after the Error):

The File <filename> cannot be opened because there are problems with the contents

I’m not having the same issue with .DOC files.

I tried to “rename” the file removing the last X from the extension, but the same problem happens.

Have you ever faced a similar problem? Do you know if there’s any solution?

Thanks ins advance!!!

1 ACCEPTED SOLUTION

matias_z
Participant
0 Kudos

None of the above helped me.

I did one more test....Using FM GUI_DOWNLOAD to download to my local PC a simple DOC and a simple DOCX document from a binary table (without storing them in the AL11 server).

Again, the DOC file was created fine with no errors.

The DOCX file is giving me the same error when opening it in my local PC:

The File <filename> cannot be opened because there are problems with the contents

And the only difference is the X at the end of the extension of the file name.

10 REPLIES 10

snipersap
Explorer
0 Kudos

Hey Matias,

I suggest you go through the following google search if not already done -

https://www.google.de/webhp?sourceid=chrome-instant&ion=1&espv=2&es_th=1&ie=UTF-8#q=docx+vs+doc

Simply said, a docx file is a compressed doc file. Although you might be able to create a doc file by transferring it via OPEN DATASET, you will not be able to do so for the docx file.

Renaming also does not help.

I am not 100% sure, however, this might be the thing you need (OLE Automation) - http://wiki.scn.sap.com/wiki/display/ABAP/Download+Data+into+Word+Document+using+OLE+Automation

0 Kudos

Hi Matias,

With the report RN2LN205N you can upload and download files to/from aplication server (AL11).

See if you can use that to download your .docx file.

Regards.

Tomas_Buryanek
Active Contributor
0 Kudos

Are you downloading exact and right amount of bytes?

This is typical mistake, when working with binary files.

-- Tomas --

matias_z
Participant
0 Kudos

None of the above helped me.

I did one more test....Using FM GUI_DOWNLOAD to download to my local PC a simple DOC and a simple DOCX document from a binary table (without storing them in the AL11 server).

Again, the DOC file was created fine with no errors.

The DOCX file is giving me the same error when opening it in my local PC:

The File <filename> cannot be opened because there are problems with the contents

And the only difference is the X at the end of the extension of the file name.

0 Kudos

We do not know how/where exactly are you getting/creating that file. How do you work with binary data (is it in XSTRING or in binary table with fixed length of lines...?)...

Also how exactly(code) are you transfering it to application server?

-- Tomas --

0 Kudos

The internal table with the data of the document is of type RSRA_T_KWF_CNTBIN, which has lines of RAW (length 1022). It's a binary table.

The code for sending that data to the app server is as follows:

DATA: l_i_content TYPE RSRA_T_KWF_CNTBIN.

FIELD-SYMBOLS: <l_wa_content> TYPE sdokcntbin.

  l_v_file = '/tmp/filename.docx'

  OPEN DATASET l_v_file FOR OUTPUT IN BINARY MODE. 

  IF sy-subrc EQ 0.

    LOOP AT l_i_content ASSIGNING <l_wa_content>.

      TRANSFER <l_wa_content>-line TO l_v_file.

    ENDLOOP.

    CLOSE DATASET l_v_file.

  ENDIF.

0 Kudos

1) Still do not know where you get that file. But lets suppose it is correct 🙂 And most important you know file size.

2) Your code to send binary data to dataset is wrong. Because moment when you TRANSFER last line of binary table you actually transfer whole line of 1022 bytes (even possible empty ones bytes).

Example: file has 5 bytes => you save 1022 bytes...

Possible solution: transfer last line with specified length (TRANSFER x to y LENGTH bytes.)

/ or convert binary table to xstring (but there might be memory problem with big file)

-- Tomas --

0 Kudos

This code made it work!!! THANKS TOMAS.

DATA: l_i_content TYPE RSRA_T_KWF_CNTBIN,

            l_v_xstring TYPE xstring.

FIELD-SYMBOLS: <l_wa_content> TYPE sdokcntbin.

  l_v_file = '/tmp/filename.docx'

  OPEN DATASET l_v_file FOR OUTPUT IN BINARY MODE.

  IF sy-subrc EQ 0.

    LOOP AT l_i_content ASSIGNING <l_wa_content>.

      l_v_xstring = <l_wa_content>-line.

      l_v_len = xstrlen( l_v_xstring ).

      l_v_pos = l_v_pos + l_v_len.

      IF l_v_pos > l_v_fsize.

        l_v_len = l_v_len - ( l_v_pos - l_v_fsize ).

      ENDIF.

      TRANSFER l_v_xstring TO l_v_file LENGTH l_v_len.

    ENDLOOP.

    CLOSE DATASET l_v_file.

  ENDIF.

0 Kudos

I have a same requirement as you had. May I know what value contains in l_v_fsize ?

raymond_giuseppi
Active Contributor
0 Kudos

Try to rename the downloaded docx file as a zip file, are you able to open it ?

(docx are zipped directory with text and binary elements, where doc were single proprietary format files)

Regards,

Raymond