[ABAP] Listenausgabe in Spool umleiten und als PDF ausgeben

DATA: it_print_params TYPE pri_params.

* Spool Druckparameter und Archivparameter lesen, bestimmen, ändern
CALL FUNCTION 'GET_PRINT_PARAMETERS'
  EXPORTING
    no_dialog              = abap_true
  IMPORTING
    out_parameters         = it_print_params
  EXCEPTIONS
    archive_info_not_found = 1
    invalid_print_params   = 2
    invalid_archive_params = 3
    OTHERS                 = 4.

IF sy-subrc = 0.
* Liste -> Spool (ID)
  NEW-PAGE PRINT ON PARAMETERS it_print_params NO DIALOG.
  WRITE: / 'Hello World'.
  NEW-PAGE PRINT OFF.

  COMMIT WORK.

  DATA: lv_bin_length TYPE i.
  DATA: lv_xstring_pdf TYPE xstring.

* Spool (ID) -> PDF
  CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
    EXPORTING
      src_spoolid              = CONV tsp01-rqident( sy-spono )
      no_dialog                = abap_true
      pdf_destination          = 'X' " xstring
      get_size_from_format     = abap_true
    IMPORTING
      pdf_bytecount            = lv_bin_length
      bin_file                 = lv_xstring_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.

  IF sy-subrc = 0.
    DATA: lv_action TYPE i.
    DATA: lv_filename TYPE string.
    DATA: lv_fullpath TYPE string.
    DATA: lv_path TYPE string.

    TRY.
* SaveDialog aufrufen
        cl_gui_frontend_services=>file_save_dialog( EXPORTING
                                                      default_extension   = 'pdf'
                                                      default_file_name   = 'ListOutput'
                                                      file_filter         = |PDF (*.pdf)\|*.pdf\|{ cl_gui_frontend_services=>filetype_all }|
                                                      prompt_on_overwrite = abap_true
                                                    CHANGING
                                                      filename          = lv_filename
                                                      path              = lv_path
                                                      fullpath          = lv_fullpath
                                                      user_action       = lv_action ).

        IF lv_action EQ cl_gui_frontend_services=>action_ok.
* xstring -> solix
          DATA(it_raw_data) = cl_bcs_convert=>xstring_to_solix( lv_xstring_pdf ).
* iTab (bytes) -> lokale Datei
          cl_gui_frontend_services=>gui_download( EXPORTING
                                                    filename     = lv_fullpath
                                                    filetype     = 'BIN'
                                                    bin_filesize = lv_bin_length
                                                  CHANGING
                                                    data_tab     = it_raw_data ).

* Browserfenster erzeugen
          DATA(o_html) = NEW cl_gui_html_viewer( parent = cl_gui_container=>default_screen ).

* PDF im ABAP-Fenster anzeigen
          o_html->show_url( url      = CONV skwf_url( lv_fullpath )
                            in_place = abap_true ).

* leere SAP-Toolbar ausblenden
          cl_abap_list_layout=>suppress_toolbar( ).

* cl_gui_container=>default_screen erzwingen
          WRITE: / |Datei erfolgreich unter { lv_fullpath } gespeichert.|.
        ENDIF.

      CATCH cx_root INTO DATA(e_txt).
        MESSAGE e_txt->get_text( ) TYPE 'S'.
    ENDTRY.
  ENDIF.
ELSE.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

Links