cancel
Showing results for 
Search instead for 
Did you mean: 

PDF doc error : filedownloadUI vs. cl_wd_runtimeservices=>attach_file_to

Former Member
0 Kudos

I have a strange problem.

I need to download a pdf doc from DMS. I got the external bapi call that returns the file binary data as array of 2550 length rawdata ('x') type.

I convert this into XSTRING and use filedownloadUI to open it.

Works FINE!!

However, the

following code

, attached to a button action, calling attach_file_to_response

does not work.


  call method cl_wd_runtime_services=>attach_file_to_response
    EXPORTING
      i_filename  = line_Filecontent_Node-filename
      i_content   = line_Filecontent_Node-filecontent
      i_mime_type = line_Filecontent_Node-mimetype.
*    i_in_new_window = abap_true
*    i_inplace       = abap_false.

The following code, linked to

filedownloadUI is working:


………
types:  char3(3).
types:  char255(255).
data: dappl type char3.
data: filename type char255.
data: dms_content type table of YBAPI_DMSCONTENT initial size 0.
field-symbols <content> like line of dms_content.
data: BIN_FILESIZE              TYPE      I.
types: field2550(2550) type x.
data: content_binary type table of field2550 initial size 0.
field-symbols <content_binary_row> like line of content_binary.
data: loopCount type i,
      xstringTab type table of xstring.
data xstringRow  type xstring.
data datastream  type xstring.

***** for xstring conversion ******
data conv_out type ref to cl_abap_conv_out_ce.
conv_out = cl_abap_conv_out_ce=>create( encoding = 'UTF-8' ).
  loopCount = 0.
  data: counter type i,
        xlen type i,
        totalRead type  i,
        remain2read type i.
  loop at dms_content assigning <content>.
    bin_filesize = <content>-length.
    counter = <content>-counter.
    loopCount = loopCount + 1.
      xlen = 2550.
      at last.
        totalRead = ( loopCount - 1 ) * 2550.
        remain2read = <content>-length - totalRead.
        xlen = remain2read . "603.
      endat.
    conv_out->convert(
    exporting
      data = <content>-data(xlen)
    importing
      buffer = xstringRow ).
    append xstringRow to xstringTab.
  endloop.
  concatenate LINES OF xstringTab into datastream in byte mode.

  Stru_Filecontent_Node-FILECONTENT = datastream.  
 
  case dappl.
    when 'doc' or 'DOC'.
        Stru_Filecontent_Node-MIMETYPE = 'application/word'.
    when 'xls' or 'XLS'.
        Stru_Filecontent_Node-MIMETYPE = 'application/excel'.
    when  'pdf' or 'PDF'.
         Stru_Filecontent_Node-MIMETYPE = 'application/pdf'.
    when others.
          Stru_Filecontent_Node-MIMETYPE = 'plain/text'.
  endcase.
  node->bind_structure( Stru_Filecontent_Node ).
endmethod.

However, both segments of code works for other types of file, like office docs, tiff image, jpg, etc.

Only on PDF, we have problem.

Please help.

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member497277
Participant
0 Kudos

Hello Cathy:

What' s the external bapi call that returns the file binary data as array of 2550 length rawdata ('x') type???.

Regards.

Ana.

SergioFerrari
Active Contributor
0 Kudos

What do you mean with "does not work"?

Sergio

Former Member
0 Kudos

After clearing the buffer, the function call works fine.

Thanks.


    clear: xstringtab, bin_filesize.
    clear datastream.

Former Member
0 Kudos

Hi Cathy,

Im also developing a WDA application to download a document from DMS, Can u share the Function module which returns the X string value, so that i can use the file download UI element to download the Document...

Actually i tried calling the FM CV120_Start_application, but im getting "Not supported by Gui" Exception...

Please help me Cathy, its really urgent....

Thanks in advance....

James...