This is a simple routine to save your smartform into a PDF file:

” Local Vars

DATA: lc_fm_name      TYPE rs38l_fnam,

      ls_control_par  TYPE ssfctrlop,

      ls_job_output   TYPE ssfcrescl,

      lc_file         TYPE string,

      lt_lines        TYPE TABLE OF tline,

      li_pdf_fsize    TYPE i,

      ls_pdf_string_x TYPE xstring,

      ls_pdf          TYPE char80,

      lt_pdf          TYPE TABLE OF char80.

” Get smartform function module name

CALL FUNCTION ‘SSF_FUNCTION_MODULE_NAME’

  EXPORTING

    formname           = ‘ZFORMNAME’  ” <- Set your smartform name

  IMPORTING

    fm_name            = lc_fm_name

  EXCEPTIONS

    no_form            = 1

    no_function_module = 2

    OTHERS             = 3.

ls_control_par-no_dialog = ‘X’.  ” No dialog window

ls_control_par-getotf    = ‘X’.  ” Get otf data

ls_control_par-langu     = sy-langu.

” Call smartform FM

” NOTE: You have to add your custom SF parameters in this call

CALL FUNCTION lc_fm_name

  EXPORTING

    control_parameters = ls_control_par

  IMPORTING

    job_output_info    = ls_job_output

  EXCEPTIONS

    formatting_error   = 1

    internal_error     = 2

    send_error         = 3

    user_canceled      = 4

    OTHERS             = 5.

” Convert smartform OTF to PDF

CALL FUNCTION ‘CONVERT_OTF’

  EXPORTING

    format                = ‘PDF’

  IMPORTING

    bin_filesize          = li_pdf_fsize

    bin_file              = ls_pdf_string_x

  TABLES

    otf                   = ls_job_output-otfdata

    lines                 = lt_lines

  EXCEPTIONS

    err_max_linewidth     = 1

    err_format            = 2

    err_conv_not_possible = 3

    err_bad_otf           = 4

    OTHERS                = 5.

” Convert xstring to binary

CALL FUNCTION ‘SCMS_XSTRING_TO_BINARY’

  EXPORTING

    buffer     = ls_pdf_string_x

  TABLES

    binary_tab = lt_pdf.

lc_file = ‘dir/sfname.pdf’.

” Save file using dataset, can be done with gui_services too

OPEN DATASET lc_file FOR OUTPUT IN BINARY MODE.

IF sy-subrc IS INITIAL.

  LOOP AT lt_pdf INTO ls_pdf.

    TRANSFER ls_pdf TO lc_file

      NO END OF LINE.

  ENDLOOP.

  CLOSE DATASET lc_file.

ENDIF.

You can use this to insert a button to save as pdf directly in your report.

New NetWeaver Information at SAP.com

Very Helpfull

 

 

User Rating: Be the first one !