메뉴 건너뛰기

SAP 한국 커뮤니티

report to PDF file

아밥뽀 2014.03.19 04:20 조회 수 : 4756

data l_spoolno type sy-spono.

data l_xstring type xstring.

data l_solix type solix_tab.

AT USER-COMMAND.

CASE SY-UCOMM.

WHEN 'PDF'.

  CALL FUNCTION 'Z_CONVERT_TO_PDF1'

    EXPORTING

      i_repid    = sy-repid

      i_linsz    = sy-linsz

      i_download = space

    IMPORTING

      e_spono    = l_spoolno

      e_xstring  = l_xstring

      e_solix    = l_solix.

ENDCASE.

  CALL FUNCTION 'Z_CONVERT_TO_PDF1'

    EXPORTING

     i_filename = 'C:test.pdf'

      i_repid    = sy-repid

      i_linsz    = 300

      i_download = 'X'

    IMPORTING

      e_spono    = l_spoolno

      e_xstring  = l_xstring

      e_solix    = l_solix.

 

Below is the Code for it..

FUNCTION z_convert_to_pdf1.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(I_FILENAME) TYPE  STRING DEFAULT 'C:temptest.pdf'
*"     REFERENCE(I_PAART) TYPE  SYPAART DEFAULT 'X_65_132'
*"     REFERENCE(I_REPID) TYPE  SYREPID
*"     REFERENCE(I_LINSZ) TYPE  SYLINSZ
*"     REFERENCE(I_DOWNLOAD) TYPE  CHAR1 DEFAULT 'X'
*"  EXPORTING
*"     REFERENCE(E_SPONO) TYPE  RSPOID
*"     REFERENCE(E_XSTRING) TYPE  XSTRING
*"     REFERENCE(E_SOLIX) TYPE  SOLIX_TAB
*----------------------------------------------------------------------

  DATA:    l_params TYPE pri_params,
           l_valid TYPE string,
           w_spool_nr LIKE tsp01-rqident.
  DATA:    l_repid TYPE sy-repid.
  DATA:    l_acttime    TYPE rslgtime,
           l_timestamp  TYPE timestamp.
  DATA:    l_range_acttime TYPE RANGE OF rslgtime WITH HEADER LINE.

*Internal table for Selection Screen
  DATA: BEGIN OF it_rsparams OCCURS 0.
          INCLUDE STRUCTURE rsparams.
  DATA: END OF it_rsparams.

  DATA: lt_pdf TYPE TABLE OF tline,
        ls_pdf TYPE tline.
  DATA:
   pdf_bytecount                  TYPE i,
   pdf_spoolid                    TYPE tsp01-rqident,
   otf_pagecount                  TYPE i,
   btc_jobname                    TYPE tbtcjob-jobname,
   btc_jobcount                   TYPE tbtcjob-jobcount,
   bin_file                       TYPE xstring.

  l_repid = i_repid.

*TO GET PRINT PARAMETERS
  CALL FUNCTION 'GET_PRINT_PARAMETERS'
    EXPORTING
      immediately            = space
      no_dialog              = 'X'
    IMPORTING
      out_parameters         = l_params
      valid                  = l_valid
    EXCEPTIONS
      archive_info_not_found = 1
      invalid_print_params   = 2
      invalid_archive_params = 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_valid NE 'X'.
    STOP.
  ENDIF.

* Store the current selection screen details
  CALL FUNCTION 'RS_REFRESH_FROM_SELECTOPTIONS'
    EXPORTING
      curr_report     = l_repid
    TABLES
      selection_table = it_rsparams.

  IF i_linsz IS NOT INITIAL.
    l_params-linsz = i_linsz.
  ENDIF.
  IF i_paart IS NOT INITIAL.
    l_params-paart = i_paart.
  ENDIF.

*Create System Log Time Before spool
  CLEAR l_acttime.
  CONVERT DATE sy-datum TIME sy-uzeit
  INTO TIME STAMP l_timestamp TIME ZONE sy-zonlo.
  l_acttime(14) = l_timestamp.
  CONCATENATE l_acttime '00' INTO l_acttime.
  l_range_acttime-sign   = 'I'.
  l_range_acttime-option = 'BT'.
  l_range_acttime-low    = l_acttime.

*Submit Report
  SUBMIT (l_repid) WITH SELECTION-TABLE it_rsparams
                    TO SAP-SPOOL
                    SPOOL PARAMETERS l_params
                    WITHOUT SPOOL DYNPRO
                    AND RETURN.

*Create System Log Time Right after spool
  CLEAR l_acttime.
  CONVERT DATE sy-datum TIME sy-uzeit
  INTO TIME STAMP l_timestamp TIME ZONE sy-zonlo.
  l_acttime(14) = l_timestamp.
  CONCATENATE l_acttime '00' INTO l_acttime.
  l_range_acttime-high    = l_acttime.
  APPEND l_range_acttime.

*SELECT THE RECENTLY CREATED SPOOL
  SELECT MAX( rqident ) INTO w_spool_nr FROM tsp01
         WHERE rqclient  = sy-mandt
         AND   rq0name   = l_params-prdsn
         AND   rq1name   = l_params-pdest
         AND   rq2name   = l_params-plist
         AND   rqowner   = l_params-prrec
         AND   rqcretime IN  l_range_acttime.

  e_spono = w_spool_nr.

*Get Xstring PDF
  CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
    EXPORTING
      src_spoolid          = w_spool_nr
      no_dialog            = space
      pdf_destination      = 'X'
      get_size_from_format = space
    IMPORTING
      pdf_bytecount        = pdf_bytecount
      pdf_spoolid          = pdf_spoolid
      btc_jobname          = btc_jobname
      btc_jobcount         = btc_jobcount
      bin_file             = e_xstring
    TABLES
      pdf                  = lt_pdf.
*Get tab PDF
  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
      buffer     = e_xstring
    TABLES
      binary_tab = e_solix.

*Download Directly to the Location
  IF i_download EQ 'X'.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        bin_filesize = pdf_bytecount
        filename     = i_filename
        filetype     = 'BIN'
      TABLES
        data_tab     = e_solix.
  ENDIF.

ENDFUNCTION.