Skip to Content
0
Former Member
Nov 18, 2020 at 07:00 PM

Generate Smartform with RFC function and Download as PDF (Solved)

584 Views Last edit Nov 19, 2020 at 10:02 AM 3 rev

I added some comments for solution. Please check below codes.

************************************************************************************************************

Hi all,

I want to get smartform output from another system by using RFC function call. I made a Z* RFC function which returns PDF's

- OTF Data

- Binary Data

- XString

- Base64

Why I need that?

We have three different systems and source system. Source system has a smartform itself. Three system will be connected source system by using RFC and source system will return PDF data to which system call it.

RFC connection user is system user, not a dialog. That's why, I couldn't run any GUI services on source system. If it was dialog, there won't be any problem.

When I try download PDF data on caller system by using GUI_DOWNLOAD, PDF file is generated as damaged file and it won't be opened.

Source and call system versions are different.

What could be reason of it?

Thanks,

From Caller System; It is damaged.

From Source System; It works.

Here is what I've used on source system to generate PDF

  ls_output_options-tdarmod = '1'.
  ls_output_options-tdnoprint = 'X'.
  ls_output_options-tddest = 'LOCL'.
  ls_output_options-tdimmed = 'X'.
  ls_output_options-tdcopies = 1.
  ls_output_options-tdreceiver = sy-uname.

  ls_control_params-no_dialog = 'X'.
  ls_control_params-getotf = 'X'.
  ls_control_params-langu = 'E'.
  ls_control_params-device = 'PRINTER'.

After getting OTF; Conversions and Download

*Solution 1: Use CONVERT_OTF instead of CONVERT_OTF_2_PDF, if you need XSTRING

  CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
      format                = 'PDF'
      max_linewidth         = 132
    IMPORTING
      bin_filesize          = ef_bin_filesize
      bin_file              = ef_xstring
    TABLES
      otf                   = lt_otf
      lines                 = et_lines
    EXCEPTIONS
      err_max_linewidth     = 1
      err_format            = 2
      err_conv_not_possible = 3
      err_bad_otf           = 4
      OTHERS                = 5.
  IF sy-subrc <> 0.

  ENDIF.

*  CALL FUNCTION 'CONVERT_OTF_2_PDF'
*    EXPORTING
*      use_otf_mc_cmd         = space
*    IMPORTING
*      bin_filesize           = ef_bin_filesize
*    TABLES
*      otf                    = ls_job_output_info-otfdata
*      doctab_archive         = lt_docs
*      lines                  = et_lines
*    EXCEPTIONS
*      err_conv_not_possible  = 1
*      err_otf_mc_noendmarker = 2
*      OTHERS                 = 3.
*  IF sy-subrc NE 0.
*    RETURN.
*  ENDIF.

*  CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
*    EXPORTING
*      input_length = ef_bin_filesize
*    IMPORTING
*      buffer       = ef_xstring
*    TABLES
*      binary_tab   = et_lines
*    EXCEPTIONS
*      failed       = 1
*      OTHERS       = 2.
*  IF sy-subrc NE 0.
*    RETURN.
*  ENDIF.

  CALL FUNCTION 'SCMS_BASE64_ENCODE_STR'
    EXPORTING
      input  = ef_xstring
    IMPORTING
      output = ef_base64.

  CALL METHOD cl_gui_frontend_services=>gui_download
    EXPORTING
      bin_filesize            = ef_bin_filesize
      filename                = 'C:\Users\onder\Desktop\From_Source.pdf'
      filetype                = 'BIN'
    CHANGING
      data_tab                = et_lines[]
    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.
     RETURN
  ENDIF.

On caller system,

   CALL FUNCTION 'ZGETPDF' DESTINATION ap_dest
      EXPORTING
        it_belnr              = lt_belnr[]
      IMPORTING
        et_message            = lt_ret[]
        ef_bin_filesize       = lf_bin_filesize
        ef_xstring            = lf_xstring
        ef_base64             = lf_base64
      TABLES
        et_lines              = lt_lines
      EXCEPTIONS
        communication_failure = 1
        system_failure        = 2
        OTHERS                = 3.
    IF sy-subrc NE 0.
      RETURN.
    ENDIF.   

*    CALL FUNCTION 'SCMS_BASE64_DECODE_STR'
*      EXPORTING
*        input  = lf_base64
*      IMPORTING
*        output = lf_xstring
*      EXCEPTIONS
*        failed = 1
*        OTHERS = 2.
*

* Solution 2: lt_lines must be SOLIX_TAB instead of TLINE.

    CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
      EXPORTING
        buffer     = lf_xstring
      TABLES
        binary_tab = lt_solix_tab.

*    CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
*      EXPORTING
*        buffer     = lf_xstring
*      TABLES
*        binary_tab = lt_lines.

    CALL METHOD cl_gui_frontend_services=>gui_download
      EXPORTING
        bin_filesize            = lf_bin_filesize
        filename                = 'C:\Users\onder\Desktop\From_Caller.pdf'
        filetype                = 'BIN'
      CHANGING
        data_tab                = lt_solix_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.
      RETURN.
    ENDIF.

Attachments

2zxzd.png (13.6 kB)
xfjgj.png (77.2 kB)