Çoklu PDF Çıktı Alınması

Tek bir `FP_JOB_OPEN` - `FP_JOB_CLOSE` aralığına birden fazla PDF çıktı dökümanı eklenebilir. Tek PDF içinde birden fazla formun birleştirilmesi. Formlar farklı tipte olabilir. Preview ile formlar merge edilmiş halde gösterilemez. O yüzden local`e indirilir. Sonra execute ile localden okunur.



  DATA ls_docparams    TYPE sfpdocparams,
         ls_outputparams TYPE sfpoutputparams,
         ls_formoutput   TYPE fpformoutput,
         gv_fname        TYPE funcname,
         lv_name         TYPE string,
         lv_dir          TYPE string,
         lt_att_content_hex TYPE solix_tab.
  DATA lt_formoutput   TYPE tfpcontent


*  CALL METHOD cl_gui_frontend_services=>directory_browse
*    EXPORTING
*      initial_folder       = `C:`
*    CHANGING
*      selected_folder      = lv_dir
*    EXCEPTIONS
*      cntl_error           = 1
*      error_no_gui         = 2
*      not_supported_by_gui = 3
*      OTHERS               = 4.

  CALL METHOD cl_gui_frontend_services=>get_temp_directory
    CHANGING
      temp_dir             lv_dir.

  CALL METHOD cl_gui_cfw=>update_view.

  CHECK sy-subrc AND lv_dir IS NOT INITIAL.

  CALL FUNCTION `FP_FUNCTION_MODULE_NAME`
    EXPORTING
      i_name     `ZMM_009_AF_INVOICE_REPORT`
    IMPORTING
      e_funcname gv_fname.
  IF sy-subrc <> 0.
  ENDIF.

  DATAlo_pdf_merger TYPE REF TO cl_rspo_pdf_merge.
  CREATE OBJECT lo_pdf_merger.

    ls_outputparams-getpdf    abap_true.
    ls_outputparams-nodialog  abap_true.
    ls_outputparams-preview   abap_false.
    ls_outputparams-bumode    `M`.
    "ls_outputparams-assemble  = `S`.
    ls_outputparams-dest      `LP01`.
    ls_outputparams-reqnew    abap_true.

  CALL FUNCTION `FP_JOB_OPEN`
    CHANGING
      ie_outputparams ls_outputparams
    EXCEPTIONS
      cancel          1
      usage_error     2
      system_error    3
      internal_error  4
      OTHERS          5.
  IF sy-subrc <> 0.
  ENDIF.

  LOOP AT IT_LIFNR_VERUR INTO DATA(ls_lifnr_verur).
    CALL FUNCTION gv_fname
      EXPORTING
        /1bcdwb/docparams  ls_docparams
        i_verur            ls_lifnr_verur-verur
        i_lifnr            ls_lifnr_verur-lifnr
      IMPORTING
        /1bcdwb/formoutput ls_formoutput
      EXCEPTIONS
        usage_error        1
        system_error       2
        internal_error     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.
      EXIT.
    ENDIF.

    lo_pdf_merger->add_documentls_formoutput-pdf ).
  ENDLOOP.

  lo_pdf_merger-merge_documentsIMPORTING merged_document DATA(lv_pdf_merged).

*  CALL FUNCTION `FP_GET_PDF_TABLE`
*  IMPORTING
*    e_pdf_table = lt_formoutput.


*  LOOP AT lt_formoutput INTO DATA(lwa_form).
*    lo_pdf_merger->add_document( lwa_form ).
*  ENDLOOP.


  CALL FUNCTION `FP_JOB_CLOSE`
    EXCEPTIONS
      usage_error    1
      system_error   2
      internal_error 3
      OTHERS         4.

  lv_name lv_dir && `` && `invoice` && `.` && `pdf`.

  CALL FUNCTION `SCMS_XSTRING_TO_BINARY`
    EXPORTING
      buffer     lv_pdf_merged
    TABLES
      binary_tab lt_att_content_hex.

  CALL METHOD cl_gui_frontend_services=>gui_download
    EXPORTING
      filename                lv_name
      filetype                `BIN`
    CHANGING
      data_tab                lt_att_content_hex
    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
      not_supported_by_gui    22
      error_no_gui            23
      OTHERS                  24.

  IF sy-subrc EQ 0.
    CALL METHOD cl_gui_frontend_services=>execute
      EXPORTING
        document               lv_name
        synchronous            `X`
      EXCEPTIONS
        cntl_error             1
        error_no_gui           2
        bad_parameter          3
        file_not_found         4
        path_not_found         5
        file_extension_unknown 6
        error_execute_failed   7
        synchronous_failed     8
        not_supported_by_gui   9
        OTHERS                 10.
      IF sy-subrc IS NOT INITIAL.
      ENDIF.
  ENDIF.

  CLEAR lv_pdf_merged.