cancel
Showing results for 
Search instead for 
Did you mean: 

How to download pdf from sap to desktop in a folder in Web Dynpro

satya-dev
Participant
0 Kudos

Hi experts,

I have to download pdf on a button click from sap to our local system in web Dynpro. I am using  client_window->client->attach_file_to_response

method but it take xstring as import parameter. problem is that i have a custom FM for converting file into pdf it export parameter as solisti1 type.

if i pass this to attach_file_response it shows error.

Any kind of suggestion will be appreciated .

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Satya,

Check this for working code..

Issue in opening Notepad attachment using class CL_FITV_GOS=>GET_CONTENT | SAP Yard

Basically you need to convert your solisti1 data to hex and call the method as shown below.

CALL FUNCTION 'SCMS_TEXT_TO_XSTRING'

                         IMPORTING

                           buffer   = lv_content_hex

                         TABLES

                           text_tab = lt_solisti1   " Your pdf data

                         EXCEPTIONS

                           failed   = 1

                           OTHERS   = 2.


if sy-subrc eq 0.

*    Open File content

                   CALL METHOD cl_wd_runtime_services=>attach_file_to_response

                     EXPORTING

                       i_filename      = lv_filename

                       i_content       = lv_content_hex

                       i_mime_type     = lv_str_mimetype

                       i_in_new_window = lv_new_window

                       i_inplace       = lv_new_window.


endif.

Regards,

Raju

satya-dev
Participant
0 Kudos

Hi Raju,

Thanks for your response.

But my requirement is different . It is like that, When i click on Download button it should download file into  a folder without asking anything .

method attach_file_to_response ask for save cancel and open, that i don't want.  

former_member197475
Active Contributor
0 Kudos

Hi Satya,

I don't think, it will be feasible.

When you click on download button, browser prompts you for several actions. It is purely restricted for security purposes from browser level.

You can use class CL_GUI_FRONTEND_SERVICES for downloading directly into the preferred location. But it won't help us in webdynpro abap. As this approach won't support webui.

For least you can try the below option

BR,

RAM.

Former Member
0 Kudos

Hi Satya,

You can use the GUI_DOWNLOAD as shown below, if you do not need a pop up to confirm the path.

Please let me know, if you still have issue.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

     EXPORTING

       buffer     = pwa_output-pdf

     TABLES

       binary_tab = data_tab.

*  l_lessor =   pwa_output-lifnr.

filename = 'C:\20150622\scn.pdf'


   cl_gui_frontend_services=>gui_download(

   EXPORTING

   filename = filename

   filetype = 'BIN'

   CHANGING

   data_tab = data_tab ).


Regards,

Raju

0 Kudos

Hi satya dwivedi,

If you want download the content into PDF then you must convert into Xtring format and then

pass into client_window->client->attach_file_to_response.

Do like below,

Use the FM ,

STR = SOLISTI1

****if you want in binary

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

    EXPORTING

      text   = STR

    IMPORTING

      buffer = XSTR

***if you want in text

SCMS_BINARY_TO_TEXT

Then Use

CALL METHOD cl_wd_runtime_services=>attach_file_to_response

    EXPORTING

      i_filename      = 'Download.PDF'

      i_content       = XSTR

      i_mime_type     = 'PDF'

      i_in_new_window = abap_false

      i_inplace       = abap_false

Hope it may help you.

Regards,

Sri.

satya-dev
Participant
0 Kudos

I am adding code

DATA text      TYPE   string.

DATA xtext     TYPE  xstring.

DATA filename  TYPE   string.

DATA lv_str    TYPE   string VALUE 'Account Receivable' .

DATA lt_pack_list  TYPE TABLE OF sopcklsti1.

DATA ls_pack_list  TYPE          sopcklsti1.

DATA ls_pack       TYPE          sopcklsti1.

DATA lt_pdf        TYPE TABLE OF   solisti1.

DATA ls_pdf        TYPE            solisti1.

DATA lv_char       TYPE TABLE OF   char255.

datalv_xstr type xstring.

data : lo_conv type ref to cl_abap_conv_obj.

create object lo_conv.

PARAMETERS p_inv   TYPE  vbeln_va .

PARAMETERS p_cust  TYPE  kunnr .

  CALL FUNCTION 'ZIW_ATTACH'

     EXPORTING

       iv_invoice  p_inv                      "invoice number

       iv_customer p_cust                  "customer number

     IMPORTING

       ls_packlist = ls_pack

     TABLES

       et_pdf      = lt_pdf.

"*Append the attachemnt packlist to the existing packlist

APPEND ls_pack TO lt_pack_list.

   text = lt_pdf .

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

   EXPORTING

     text   = text

   IMPORTING

     buffer = xtext.

CONCATENATE lv_str '.pdf' INTO filename .

CALL METHOD cl_wd_runtime_services=>attach_file_to_response

   EXPORTING

     i_filename      = filename

     i_content       = xtext

     i_mime_type     = 'PDF'

     i_in_new_window = ABAP_FALSE

     i_inplace       = ABAP_FALSE .


------------------------------------------------------------------------------------------------------------------------------------


Error- It says that LT_PDF  can not be converted to TEXT


0 Kudos

Hi Satya,

I may wrong, please fallow what Raju Shrestha suggested, i think it seems to be working.

Regards,

Sri.