Skip to Content
Technical Articles
Author's profile photo Rohith Ramagiri

Download adobe form into local system in PDF format.

Introduction:

I came across a situation where my client wants to download and save adobe form into local system in PDF format from the report on the user confirmation. Confirmation message is shown when the user clicks back from output screen.

The below are the following function modules and methods:

  • FP_JOB_OPEN
  • FP_FUNCTION_MODULE_NAME
  • FP_JOB_CLOSE
  • POPUP_TO_CONFIRM
  • SCMS_XSTRING_TO_BINARY
  • cl_gui_frontend_services=>gui_download
  • cl_gui_frontend_services=>execute

Step 1:

Call function ‘FP_JOB_OPEN’.

Here, we pass the form’s output parameters into lv_fp_outputparams.

    CALL FUNCTION 'FP_JOB_OPEN'
      CHANGING
        ie_outputparams = lv_fp_outputparams
      EXCEPTIONS
        cancel          = 1
        usage_error     = 2
        system_error    = 3
        internal_error  = 4
        OTHERS          = 5.
    IF sy-subrc <> 0.

    ENDIF.

 

Step 2:

Call function ‘FP_FUNCTION_MODULE_NAME’

Gets the technical name of the generated form.

      CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'           "& Form Processing Generation
        EXPORTING
          i_name     = '     '                          "&Adobe form name
        IMPORTING
          e_funcname = lv_fm_name.
      IF sy-subrc <> 0.
      ENDIF.
    ELSE.

 

Step 3:

Call function ‘lv_fm_name’ (This variable contains technical name of the form). Here, we get a pdf in xsting format generated in ‘lv_fp_formutput-pdf’.

    CALL FUNCTION lv_fm_name
      EXPORTING
        /1bcdwb/docparams  = lv_fp_docparams
        gw_ers             = gw_ers
      IMPORTING
        /1bcdwb/formoutput = lv_fp_formoutput
      EXCEPTIONS
        usage_error        = 1
        system_error       = 2
        internal_error     = 3.
    IF sy-subrc <> 0.
    ENDIF.

 

Step 4:

Call function ‘FP_JOB_CLOSE’.

    CALL FUNCTION 'FP_JOB_CLOSE'
*      IMPORTING
*        e_result       = 
      EXCEPTIONS
        usage_error    = 1
        system_error   = 2
        internal_error = 3
        OTHERS         = 4.
    IF sy-subrc <> 0.
    ENDIF.

 

Step 5:

Call function ‘POPUP_TO_CONFIRM’ (The is optional).

We use this function module to generate an editable pop up to confirm saving the form into local system.

      CALL FUNCTION 'POPUP_TO_CONFIRM'
        EXPORTING
          text_question         = text_question
          display_cancel_button = ' '
        IMPORTING
          answer                = answer
        EXCEPTIONS
          text_not_found        = 1
          OTHERS                = 2.

 

Step 6:

I have executed the following FM’s when user click’s ‘Yes’ in the step 5.

Call function ‘SCMS_XSTRING_TO_BINARY’.

This function module converts xstring data to binary data from lv_fp_formoutput-pdf into data_tab.

        CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
          EXPORTING
            buffer     = lv_fp_formoutput-pdf
          TABLES
            binary_tab = data_tab.

 

Step 7:

Using this method we can download the generated form. Here, we have to mention the desired file path in the exporting parameter ‘Filename’. We can save and open our file in the desired path.

CALL METHOD cl_gui_frontend_services=>gui_download
          EXPORTING
            filename                = filename1
            filetype                = 'BIN'
          CHANGING
            data_tab                = data_tab
          EXCEPTIONS
            file_write_error        = 1
            no_batch                = 2
            gui_refuse_filetransfer = 3
            invalid_type            = 4
            no_authority            = 5
            unknown_error           = 6
            header_not_allowed      = 7
            separator_not_allowed   = 8
            filesize_not_allowed    = 9
            header_too_long         = 10
            dp_error_create         = 11
            dp_error_send           = 12
            dp_error_write          = 13
            unknown_dp_error        = 14
            access_denied           = 15
            dp_out_of_memory        = 16
            disk_full               = 17
            dp_timeout              = 18
            file_not_found          = 19
            dataprovider_exception  = 20
            control_flush_error     = 21
            not_supported_by_gui    = 22
            error_no_gui            = 23
            OTHERS                  = 24.
        IF sy-subrc <> 0.
        ENDIF.

 

Step 8:

This method is optional. Here, we can able to view the saved or downloaded form in the local system or desktop.

CALL METHOD cl_gui_frontend_services=>execute
  EXPORTING
    document               = filename
  EXCEPTIONS
    cntl_error             = 1
    error_no_gui           = 2
    bad_parameter          = 3
    file_not_found         = 4
    path_not_found         = 5
    file_extension_unknown = 6
    error_execute_failed   = 7
    synchronous_failed     = 8
    not_supported_by_gui   = 9
    others                 = 10
        .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

 

Conclusion:

Using the above steps one can save the adobe form into local system in PDF format at the desired path.

 

Thanks for Reading.

Hope this post would be helpful.

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.