This program prints own classical output into spool and converts into
PDF and PDF is downloaded into desktop using GUI_DOWNLOAD as binary
file.
REPORT ZTEST_PDF_DOWNLOAD.
"Variables
DATA:
L_LAY TYPE PRI_PARAMS-PAART,
L_LINES TYPE PRI_PARAMS-LINCT,
L_COLS TYPE PRI_PARAMS-LINSZ,
L_VAL TYPE C,
L_NO_OF_BYTES TYPE I,
L_PDF_SPOOLID LIKE TSP01-RQIDENT,
L_JOBNAME LIKE TBTCJOB-JOBNAME,
L_JOBCOUNT LIKE TBTCJOB-JOBCOUNT,
SPOOLNO TYPE TSP01-RQIDENT.
*Types
TYPES:
T_PRIPAR TYPE PRI_PARAMS,
T_ARCPAR TYPE ARC_PARAMS.
"Work areas
DATA:
LW_PRIPAR TYPE T_PRIPAR,
LW_ARCPAR TYPE T_ARCPAR.
DATA:
IT_T100 TYPE T100 OCCURS 0 WITH HEADER LINE,
IT_PDF TYPE TLINE OCCURS 0 WITH HEADER LINE.
"Start-of-selection.
START-OF-SELECTION.
L_LAY = 'X_65_132'.
L_LINES = 65.
L_COLS = 132.
"Read, determine, change spool print parameters and archive parameters
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
IN_ARCHIVE_PARAMETERS = LW_ARCPAR
IN_PARAMETERS = LW_PRIPAR
LAYOUT = L_LAY
LINE_COUNT = L_LINES
LINE_SIZE = L_COLS
NO_DIALOG = 'X'
IMPORTING
OUT_ARCHIVE_PARAMETERS = LW_ARCPAR
OUT_PARAMETERS = LW_PRIPAR
VALID = L_VAL
EXCEPTIONS
ARCHIVE_INFO_NOT_FOUND = 1
INVALID_PRINT_PARAMS = 2
INVALID_ARCHIVE_PARAMS = 3
OTHERS = 4.
IF L_VAL <> SPACE AND SY-SUBRC = 0.
LW_PRIPAR-PRREL = SPACE.
LW_PRIPAR-PRIMM = SPACE.
NEW-PAGE PRINT ON
NEW-SECTION
PARAMETERS LW_PRIPAR
ARCHIVE PARAMETERS LW_ARCPAR
NO DIALOG.
ENDIF.
"Get data
SELECT *
FROM T100
INTO TABLE IT_T100
UP TO 100 ROWS
WHERE SPRSL = SY-LANGU.
" Writing to Spool
LOOP AT IT_T100.
WRITE:/ IT_T100.
ENDLOOP.
NEW-PAGE PRINT OFF.
CALL FUNCTION 'ABAP4_COMMIT_WORK'.
SPOOLNO = SY-SPONO.
"Convert spool to PDF
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
SRC_SPOOLID = SPOOLNO
NO_DIALOG = ' '
IMPORTING
PDF_BYTECOUNT = L_NO_OF_BYTES
PDF_SPOOLID = L_PDF_SPOOLID
BTC_JOBNAME = L_JOBNAME
BTC_JOBCOUNT = L_JOBCOUNT
TABLES
PDF = IT_PDF.
"Download PDF file C Drive
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = 'C:\itab_to_pdf.pdf'
FILETYPE = 'BIN'
TABLES
DATA_TAB = IT_PDF.
Serkan AKKAVAK
Computer Engineer
serkurumsal@yandex.com
Social Plugin