Posted: Wed Sep 05, 2007 10:56 am Post subject: Getting PDF file from spooling list
Author: Kyung Woo, Nam
Description
This code snippet for users to provide function like this, saving files from splooing list. You can find your own spooling list only and then choose, save it.
Code:
*********************************************************************
* Program Name : ZSDRPDF
* SAP Module : SD
* Description : PDF SAVE FROM SPOOLING LIST
* Input :
* Output :
* Initiator : Kyung Woo, Nam
* External Ref :
*********************************************************************
* Change History.
* Date Author Reason
*
*********************************************************************
Report ZSDRPDF 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.
*selection-screen begin of block blk with frame title text-001.
*parameter : zuser like tsp01-RQOWNER default sy-uname.
*selection-screen end of block blk.
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.
CALL FUNCTION 'Z_SD_PDF_CREATE'
EXPORTING
spoolno = wa_spool-rqident
p_file = l_path
IMPORTING
msgtxt = ztxt. IF sy-subrc <> 0 OR
NOT ( ztxt IS INITIAL ).
ELSE.
MESSAGE i008(zmsd) WITH 'Fail'.
ENDIF.*&---------------------------------------------------------------------*
*& 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 = zuser.
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
--> Function module : Z_SD_PDF_CREATEFUNCTION z_sd_pdf_create.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(SPOOLNO) TYPE TSP01-RQIDENT
*" REFERENCE(P_FILE) TYPE RLGRAP-FILENAME DEFAULT 'C:\file.pdf'
*" EXPORTING
*" REFERENCE(MSGTXT) TYPE CHAR50
*"----------------------------------------------------------------------
*
* External Ref : RSTXPDFT4
*
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.
TABLES: tsp01. 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.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.