Skip to Content

how to save classical report as pdf file

hi all,

i have created a classical report and now the requirement is to save that report as a pdf .

is there any FM or any other method to do so?

regards

vijay

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Sep 11, 2008 at 06:43 PM

    Hi Vijay,

    Here is what I did for the same requirement:

    Calling for the PDF File name and path to save the file

    CALL METHOD cl_gui_frontend_services=>file_save_dialog

    EXPORTING

    window_title = 'Quote Bom PDF File'

    default_file_name = l_file_name

    initial_directory = l_fullpath

    prompt_on_overwrite = 'X'

    CHANGING

    filename = l_file

    path = l_path

    fullpath = g_path

    user_action = l_user

    EXCEPTIONS

    cntl_error = 1

    error_no_gui = 2

    not_supported_by_gui = 3

    OTHERS = 4.

    IF sy-subrc <> 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    ENDIF.

    IF l_user = 0.

      • Please follow the following order for the subroutines which is creating the Spool Number, writing the*

      • statements on to the screen and then create the PDF file*

      PERFORM get_spool_created.

      PERFORM write_lines.

      NEW-PAGE PRINT OFF.

      g_spool_no = sy-spono.

      PERFORM download_as_pdf.

        • Spool Number is getting created in this routine*

        FORM get_spool_created .

        DATA: pripar TYPE pri_params,

        arcpar TYPE arc_params,

        lay TYPE pri_params-paart,

        lines TYPE pri_params-linct,

        rows TYPE pri_params-linsz.

        DATA: val(1), val1(1).

        DATA: dest TYPE pri_params-pdest VALUE 'LP01'.

        DATA: name TYPE pri_params-plist VALUE 'Testing'.

        DATA: i_pdf TYPE STANDARD TABLE OF tline.

        DATA: spono TYPE tsp01-rqident.

        CALL FUNCTION 'GET_PRINT_PARAMETERS'

        EXPORTING

        destination = dest

        no_dialog = 'X'

        immediately = ' '

        IMPORTING

        out_archive_parameters = arcpar

        out_parameters = pripar

        valid = val

        valid_for_spool_creation = val1

        EXCEPTIONS

        archive_info_not_found = 1

        invalid_print_params = 2

        invalid_archive_params = 3

        OTHERS = 4.

        IF sy-subrc NE 0.

        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

        ENDIF.

        pripar-linsz = '132'.

        pripar-paart = 'X_65_132'.

        pripar-prdsn = 'LP01'.

        CALL FUNCTION 'GET_PRINT_PARAMETERS'

        EXPORTING

        in_archive_parameters = arcpar

        in_parameters = pripar

        no_dialog = 'X'

        list_name = name

        IMPORTING

        out_archive_parameters = arcpar

        out_parameters = pripar

        valid = val

        valid_for_spool_creation = val1

        EXCEPTIONS

        archive_info_not_found = 1

        invalid_print_params = 2

        invalid_archive_params = 3

        OTHERS = 4.

        IF sy-subrc EQ 0.

        NEW-PAGE NO-TITLE NO-HEADING PRINT ON

        NEW-SECTION

        PARAMETERS pripar

        ARCHIVE PARAMETERS arcpar

        NO DIALOG.

        ELSE.

        WRITE:/ 'Unable to create spool'.

        EXIT.

        ENDIF.

        ENDFORM. " GET_SPOOL_CREATED

          • Write all your statements in this routine*

          &----


          *& Form WRITE_LINES

          &----


          • text

          ----


          • --> p1 text

          • <-- p2 text

          ----


          FORM write_lines .

          CALL THE ROUTINE WHICH WRITES ALL LINES TO THE SCREEN

          ENDFORM. " WRITE_LINES

          *Download the file as PDF

          &----


          *& Form DOWNLOAD_AS_PDF

          &----


          • text

          ----


          • --> p1 text

          • <-- p2 text

          ----


          FORM download_as_pdf .

          DATA:

          l_no_of_bytes TYPE i,

          l_pdf_spoolid LIKE tsp01-rqident,

          l_jobname LIKE tbtcjob-jobname,

          l_jobcount LIKE tbtcjob-jobcount,

          i_pdf TYPE TABLE OF tline,

          i_cpdf TYPE TABLE OF tline,

          l_spono TYPE tsp01_sp0r-rqid_char,

          l_fullpath TYPE string.

          CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

          EXPORTING

          src_spoolid = g_spool_no

          no_dialog = ' '

          IMPORTING

          pdf_bytecount = l_no_of_bytes

          pdf_spoolid = l_pdf_spoolid

          btc_jobname = l_jobname

          btc_jobcount = l_jobcount

          TABLES

          pdf = i_pdf

          EXCEPTIONS

          err_no_abap_spooljob = 1

          err_no_spooljob = 2

          err_no_permission = 3

          err_conv_not_possible = 4

          err_bad_destdevice = 5

          user_cancelled = 6

          err_spoolerror = 7

          err_temseerror = 8

          err_btcjob_open_failed = 9

          err_btcjob_submit_failed = 10

          err_btcjob_close_failed = 11

          OTHERS = 12.

          l_spono = g_spool_no.

          CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'

          EXPORTING

          spoolid = l_spono.

          CALL FUNCTION 'GUI_DOWNLOAD'

          EXPORTING

          bin_filesize = l_no_of_bytes

          filename = g_path

          filetype = 'BIN'

          TABLES

          data_tab = i_pdf

          EXCEPTIONS

          file_write_error = 1

          no_batch = 2

          gui_refuse_filetransfer = 3

          invalid_type = 4

          no_authority = 5

          unknown_error = 6.

          ENDFORM. " DOWNLOAD_AS_PDF

          Thanks.

          Respond if you need any more help.

          Add comment
          10|10000 characters needed characters exceeded