*********************************************************************
* Program Name : ZCREATEPDF
* Description : PDF SAVE FROM SPOOLING LIST
*********************************************************************
REPORT zcreatepdf NO STANDARD PAGE HEADING
MESSAGE-ID zmsd
LINE-SIZE 125
LINE-COUNT 80.
TABLES: tsp01.
TYPES: BEGIN OF ty_spool,
rqident LIKE tsp01-rqident,
rqowner LIKE tsp01-rqowner,
rqtitle LIKE tsp01-rqtitle,
chk.
TYPES: END OF ty_spool.
DATA: wa_spool TYPE ty_spool.
DATA: itb_spool TYPE ty_spool OCCURS 0.DATA: flag TYPE i.DATA: ztxt(50).
DATA: l_path TYPE rlgrap-filename.
START-OF-SELECTION.
PERFORM get_data.
END-OF-SELECTION.
PERFORM write_data.
AT LINE-SELECTION.
CLEAR ztxt.
CLEAR l_path.
l_path = 'C:\zfile.pdf'.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_filename = l_path
def_path = ''
mask = ',*.*,*.txt,*.txt.'
mode = 'S'
title = 'Choose file path to save'
IMPORTING
filename = l_path
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.
IF sy-subrc = 0.
ENDIF.
PERFORM z_pdf_create
USING wa_spool-rqident
l_path
ztxt.
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_data.
SELECT rqident rqowner rqtitle
INTO CORRESPONDING FIELDS OF TABLE itb_spool
FROM tsp01
WHERE rqowner = sy-uname.
SORT itb_spool BY rqident DESCENDING.
ENDFORM. " get_data
*&---------------------------------------------------------------------*
*& Form write_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM write_data.
CLEAR flag.
WRITE sy-uline(125).
WRITE:/ '|'.
WRITE: (15) 'Spooling Number'.
WRITE: '|', (20) 'Job Owner', '|', (80) 'Job Title', '|'.
WRITE: sy-uline(125).
LOOP AT itb_spool INTO wa_spool.
flag = sy-tabix MOD 2.
CASE flag.
WHEN 1.
FORMAT COLOR COL_NORMAL ON.
WHEN 0.
FORMAT COLOR OFF.
ENDCASE.
WRITE:/ '|'.
FORMAT HOTSPOT ON.
WRITE: (15) wa_spool-rqident.
HIDE wa_spool-rqident.
FORMAT HOTSPOT OFF.
WRITE: '|', (20) wa_spool-rqowner, '|',
(80) wa_spool-rqtitle, '|'.
WRITE: sy-uline(125).
ENDLOOP.
ENDFORM. " write_data
FORM z_pdf_create USING spoolno TYPE tsp01-rqident
p_file TYPE rlgrap-filename
msgtxt TYPE char50.
p_file = 'C:\file.pdf'.
DATA download VALUE 'X'.
DATA otf LIKE itcoo OCCURS 100 WITH HEADER LINE.
DATA cancel.
DATA pdf LIKE tline OCCURS 100 WITH HEADER LINE.
DATA doctab LIKE docs OCCURS 1 WITH HEADER LINE.
DATA: numbytes TYPE i,
arc_idx LIKE toa_dara,
pdfspoolid LIKE tsp01-rqident,
jobname LIKE tbtcjob-jobname,
jobcount LIKE tbtcjob-jobcount,
is_otf.
DATA: client LIKE tst01-dclient,
name LIKE tst01-dname,
objtype LIKE rststype-type,
type LIKE rststype-type.
SELECT SINGLE * FROM tsp01
WHERE rqident = spoolno.
IF sy-subrc <> 0.
MESSAGE e001(zmsd) WITH text-001. " Fail
EXIT.
ENDIF.
client = tsp01-rqclient.
name = tsp01-rqo1name. CALL FUNCTION 'RSTS_GET_ATTRIBUTES'
EXPORTING
authority = 'SP01'
client = client
name = name
part = 1
IMPORTING
type = type
objtype = objtype
EXCEPTIONS
fb_error = 1
fb_rsts_other = 2
no_object = 3
no_permission = 4.
IF objtype(3) = 'OTF'.
is_otf = 'X'.
ELSE.
is_otf = space.
ENDIF.
IF is_otf = 'X'.
CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = spoolno
no_dialog = ' '
IMPORTING
pdf_bytecount = numbytes
pdf_spoolid = pdfspoolid
btc_jobname = jobname
btc_jobcount = jobcount
TABLES
pdf = pdf
EXCEPTIONS
err_no_otf_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_dstdevice = 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.
CASE sy-subrc.
WHEN 0.
WHEN OTHERS.
MESSAGE e001(zmsd) WITH text-002.
"CONVERT_OTFSPOOLJOB_2_PDF Fail
EXIT.
ENDCASE.
ELSE.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = spoolno
no_dialog = ' '
IMPORTING
pdf_bytecount = numbytes
pdf_spoolid = pdfspoolid
btc_jobname = jobname
btc_jobcount = jobcount
TABLES
pdf = 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.
CASE sy-subrc.
WHEN 0.
WHEN OTHERS.
MESSAGE e001(zmsd) WITH text-003.
"CONVERT_ABAPSPOOLJOB_2_PDF Fail
EXIT.
ENDCASE.
ENDIF.
*************** download PDF file ***********
CHECK download = 'X'.
IF NOT ( jobname IS INITIAL ).
EXIT.
ENDIF.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
filename = p_file
filetype = 'BIN'
bin_filesize = numbytes
TABLES
data_tab = pdf
EXCEPTIONS
file_open_error = 1
file_write_error = 2
invalid_filesize = 3
invalid_table_width = 4
invalid_type = 5
no_batch = 6
unknown_error = 7
OTHERS = 8.
IF sy-subrc <> 0.
msgtxt = text-004. "Fail
ENDIF.
ENDFORM. "z_pdf_create
阅读(567) | 评论(0) | 转发(0) |