* We can convert abap program list to PDF
file with below source.
REPORT
ZTEST_ABAPTPDF.
TABLES:
TSP01.
DATA: MSTR_PRINT_PARMS LIKE PRI_PARAMS,
MC_VALID(1) TYPE C,
MI_BYTECOUNT TYPE I,
MI_LENGTH TYPE I,
MI_RQIDENT LIKE
TSP01-RQIDENT.
DATA: MTAB_PDF LIKE TLINE OCCURS 0,
MC_FILENAME TYPE STRING. "LIKE RLGRAP-FILENAME.
*-- SELECTION SCREEN
PARAMETERS: P_REPID LIKE SY-REPID, " Report to execute
P_LINSZ LIKE SY-LINSZ DEFAULT
132, " Line size
P_PAART LIKE SY-PAART DEFAULT
'Z_58_147'. " Paper Format
START-OF-SELECTION.
CONCATENATE 'c:\' P_REPID '.pdf'
INTO MC_FILENAME.
*-- Setup the Print Parmaters
CALL
FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
COPIES = '1'
DESTINATION = SPACE
EXPIRATION = '1'
NEW_LIST_ID = 'X'
NO_DIALOG = 'X'
USER = SY-UNAME
IMPORTING
OUT_PARAMETERS =
MSTR_PRINT_PARMS
VALID = MC_VALID.
IF MSTR_PRINT_PARMS-PDEST = SPACE. MSTR_PRINT_PARMS-PDEST = 'ZP01'. ENDIF.
MSTR_PRINT_PARMS-LINSZ = P_LINSZ.
MSTR_PRINT_PARMS-PAART = P_PAART.
SUBMIT
(P_REPID) TO SAP-SPOOL WITHOUT SPOOL DYNPRO
SPOOL PARAMETERS
MSTR_PRINT_PARMS
VIA SELECTION-SCREEN AND RETURN.
*-- Find out what the spool number is that
was just created
PERFORM GET_SPOOL_NUMBER
USING SY-REPID SY-UNAME
CHANGING
MI_RQIDENT.
*-- Convert Spool to PDF
CALL
FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
SRC_SPOOLID =
MI_RQIDENT
NO_DIALOG = SPACE
DST_DEVICE =
MSTR_PRINT_PARMS-PDEST
IMPORTING
PDF_BYTECOUNT =
MI_BYTECOUNT
TABLES
PDF =
MTAB_PDF.
CALL
METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
EXPORTING
BIN_FILESIZE =
MI_BYTECOUNT
FILENAME =
MC_FILENAME
FILETYPE = 'BIN'
CHANGING
DATA_TAB =
MTAB_PDF.
FORM GET_SPOOL_NUMBER USING F_REPID
F_UNAME
CHANGING F_RQIDENT.
DATA:
LC_RQ2NAME LIKE TSP01-RQ2NAME.
CONCATENATE F_REPID+0(8) F_UNAME+0(3)
INTO LC_RQ2NAME SEPARATED BY '_'.
SELECT * FROM TSP01 WHERE RQ2NAME
= LC_RQ2NAME
ORDER
BY RQCRETIME DESCENDING.
F_RQIDENT = TSP01-RQIDENT. EXIT.
ENDSELECT.
IF
SY-SUBRC NE 0. CLEAR F_RQIDENT. ENDIF.
ENDFORM." get_spool_number
No comments:
Post a Comment