Convert Smartform to PDF

Berikut ini step yang bisa dilakukan untuk convert smartform ke dalam bentuk PDF

  1. Gunakan Function Module (FM)SSF_FUNCTION_MODULE_NAME untuk mengetahui nama FM dari smartform yang ingin ditampilkan.
  2. Panggil FM yang didapatkan tadi, isi parameter control_parameters dan output_options agar smartform tidak akan tampil ke layar.
  3. Panggil FM CONVERT_OTF CONVERT_OTF_2_PDF dengan input parameter data otf yang dihasilkan dari FM pada step 2.
  4. Bila ingin menampilkan format PDF di layar bisa menggunakan FM HR_IT_DISPLAY_WITH_PDF
  5. Bila ingin mendownload file dalam bentuk PDF bisa menggunakan FM GUI_DOWNLOAD.

 

  DATA: ls_ssfctrlop TYPE ssfctrlop,
        ls_ssfcompop TYPE ssfcompop.
  DATA: ld_formname TYPE tdsfname,
        ld_fmname TYPE rs38l_fnam,
        ls_form_data_tab TYPE  hrcm_tcs_form_data_tab,
        ls_otf_data     TYPE ssfcrescl.
  DATA: lt_otf_final    TYPE itcoo OCCURS 0 WITH HEADER LINE,
        ld_size         TYPE i,
        ld_file         TYPE  xstring,
        lt_pdf          LIKE tline OCCURS 0 WITH HEADER LINE,
        lt_doctab       TYPE STANDARD TABLE OF docs.

**** to supress the dialog box for printer
  ls_ssfcompop-tddest     = 'LOCL'.
  ls_ssfctrlop-no_dialog  = 'X'.
  ls_ssfctrlop-preview    = space.
  ls_ssfctrlop-getotf     = 'X'.

**** call smartforms
  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      formname           = ld_formname
    IMPORTING
      fm_name            = ld_fmname
    EXCEPTIONS
      no_form            = 1
      no_function_module = 2
      OTHERS             = 3.

    CALL FUNCTION ld_fmname
      EXPORTING
        control_parameters = ls_ssfctrlop
        output_options     = ls_ssfcompop
        user_settings      = space
      IMPORTING
        job_output_info    = ls_otf_data
      EXCEPTIONS
        formatting_error   = 1
        internal_error     = 2
        send_error         = 3
        user_canceled      = 4
        OTHERS             = 5.

**** convert to PDF file
      lt_otf_final[] = ls_otf_data-otfdata[].
*      CALL FUNCTION 'CONVERT_OTF'
*        EXPORTING
*          format                = 'PDF'
*          max_linewidth         = 132
*        IMPORTING
*          bin_filesize          = ld_size
*          bin_file              = ld_file
*        TABLES
*          otf                   = lt_otf_final
*          lines                 = lt_pdf
*        EXCEPTIONS
*          err_max_linewidth     = 1
*          err_format            = 2
*          err_conv_not_possible = 3
*          err_bad_otf           = 4
*          OTHERS                = 5.

  CALL FUNCTION 'CONVERT_OTF_2_PDF'
    IMPORTING
      bin_filesize           = ld_size
    TABLES
      otf                    = lt_otf_final
      doctab_archive         = lt_doctab
      lines                  = lt_pdf
    EXCEPTIONS
      err_conv_not_possible  = 1
      err_otf_mc_noendmarker = 2
      OTHERS                 = 3.

**** display PDF
  CALL FUNCTION 'HR_IT_DISPLAY_WITH_PDF'
    TABLES
      otf_table = lt_otf_final.

**** download PDF
  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      bin_filesize            = ld_size
      filename                = 'D:\TEST.PDF'
      filetype                = 'BIN'
*    IMPORTING
*      filelength              =
    TABLES
      data_tab                = lt_pdf
    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
      OTHERS                  = 22.
Advertisements

2 comments

  1. Hello! Thank for the post.
    When you run the program I export a PDF file empty.
    displays the following message:

    Acrobat could not open ‘TEST.PDF’ because it is either not a supported file type or because the file has been damager (For example, it was sent as an email attachment and wasn’t correctly decoded).
    To create an Adobe PDF document, go to the source application. Then printer the document to Adobe PDF.

    Regards.

    • Hi JGonzales!

      Thx for your correction. I updated the post with the correct FM to convert the OTF to PDF using CONVERT_OTF_2_PDF.

      I should work fine now 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s