Skip to Content

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

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 .

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Jun 19, 2015 at 12:17 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jun 19, 2015 at 03:24 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member satya dwivedi

      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