Skip to Content
0
Apr 27, 2009 at 10:43 AM

Download PDF file from Application Server in BSP

233 Views

Hello,

We have a requirement on which we want to download a PDF file stored in Application server using BSP application. I have used function module ARCHIVFILE_SERVER_TO_CLIENT but this FM will help only if i want to download file from GUI it won't work in BSP application.

Further i have used class CL_BSP_UTILITY and download method to download file from application server but it is not working in desired manner.

I am attaching my code for your reference:

DATA: BUTTON_EVENT TYPE REF TO CL_HTMLB_EVENT_BUTTON ,

           EVENT TYPE REF TO IF_HTMLB_DATA.

DATA: LS_HOURS LIKE LINE OF GT_HOURS.

DATA STR TYPE STRING.

DATA: OUTPUT TYPE STRING ,

          L_XSTRING TYPE XSTRING ,

           APP_TYPE TYPE STRING.  



EVENT = CL_HTMLB_MANAGER=>GET_EVENT( REQUEST ).

DATA PHY_NAME_OUT     TYPE SAPB-SAPPFAD.



IF EVENT IS NOT INITIAL AND EVENT->EVENT_NAME = HTMLB_EVENTS=>BUTTON .

  BUTTON_EVENT ?= EVENT .

  CASE EVENT->EVENT_SERVER_NAME.

    WHEN 'test' .

      IF GT_HOURS IS NOT INITIAL.


        PHY_NAME_OUT = '/usr/sap/put/form16//01000200_2007.PDF'.

      OPEN DATASET PHY_NAME_OUT FOR INPUT IN TEXT MODE ENCODING DEFAULT.
        IF SY-SUBRC IS INITIAL.
          DO.
            READ DATASET PHY_NAME_OUT INTO STR.
            IF SY-SUBRC IS INITIAL.
            CONCATENATE
                OUTPUT
                str
                cl_abap_char_utilities=>cr_lf

 INTO output SEPARATED BY space. "cl_abap_char_utilities=>horizontal_tab


            ELSE.
              EXIT.
            ENDIF.
          ENDDO.
        ENDIF.




*LOOP AT gt_hours INTO ls_hours.
*
*CONCATENATE
*
*OUTPUT
*
*ls_hours-hour
*
*cl_abap_char_utilities=>cr_lf
*
*INTO output SEPARATED BY space. "cl_abap_char_utilities=>horizontal_tab
* .
*
*.
*
*
*
*ENDLOOP.

        APP_TYPE = 'APPLICATION/PDF;charset=utf-16le'.
*
        CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
          EXPORTING
            TEXT     = OUTPUT
            MIMETYPE = 'APPLICATION/PDF;charset=utf-16le'
          IMPORTING
            BUFFER   = L_XSTRING.





        CONCATENATE CL_ABAP_CHAR_UTILITIES=>BYTE_ORDER_MARK_LITTLE

        L_XSTRING

        INTO L_XSTRING IN BYTE MODE.



        CALL METHOD CL_BSP_UTILITY=>DOWNLOAD

        EXPORTING

        OBJECT_S = L_XSTRING

        CONTENT_TYPE = APP_TYPE

        CONTENT_DISPOSITION = 'attachment;filename=webforms.pdf'

        RESPONSE = _M_RESPONSE

        NAVIGATION = NAVIGATION.

      ENDIF.

  ENDCASE.

ENDIF.

From this code i am able to download PDF file but it is not opening in local machine.

If any other way to download file then please suggest.

waiting for ur reply.

Regards,

Gagan