Skip to Content

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.

To report this post you need to login first.

7 Comments

You must be Logged on to comment or reply to a post.

    1. Guilherme Frisoni Post author

      Hi Maheshkumar,

      you have to check your smartforms import/export parameters to add in this call.

      As this is a dynamic call, parameters will change for each smartform.

      I suggest you get smartform FM name and use ABAP Pattern (CTRL+F6) for FM.

      After the pattern is loaded, change your FM name for lc_fm_name.

      Regards,

      Guilherme Frisoni

      (0) 
      1. Maheshkumar gattu

        Hi Guilherme Frisoni,

        I thought it works for any smartform, i created a se38 program and passing the formname from selection screen. So that might be the reason for each SF the parameters get changes so it might an issue….

        Okay thanks for your post and quick reply.

        Regards,

        Mahesh

        (0) 
  1. SHRIKANT PADWALE

    hellow friend,

       as per me we can not call ” PDF! ” transaction at background b’cos  table “TSTC”not containg any data for pdf! so  it will give run time dump.

    (0) 

Leave a Reply