Sap Spool To Pdf Conversion Program
Dear SAP Community Member, In order to. Snippet ABAP Convert Spool to PDF and Stores it in Application server. This program will convert spools to PDF. Spool to pdf program sap This will convert print preview of output in to PDF which can be saved. A Execute the program RSTXPDFT4 in SE38 by entering the spool.The.
.&-.& Report ZSPOOLTOPDF.&.&-.& Converts spool request into PDF document and emails it to.& recipicant.&.& Execution.& -.& This program must be run as a background job in-order for.& the write commands to create a Spool request rather than.& be displayed on screen.&-. REPORT zspooltopdf. PARAMETER: pemail1 LIKE somlreci1-receiver DEFAULT 'abap@sapdev.co.uk', psender LIKE somlreci1-receiver DEFAULT 'abap@sapdev.co.uk', pdelspl AS CHECKBOX.DATA DECLARATION DATA: gdrecsize TYPE i. Spool IDs TYPES: BEGIN OF ttbtcp. INCLUDE STRUCTURE tbtcp.
TYPES: END OF ttbtcp. DATA: ittbtcp TYPE STANDARD TABLE OF ttbtcp INITIAL SIZE 0, watbtcp TYPE ttbtcp. Job Runtime Parameters DATA: gdeventid LIKE tbtcm-eventid, gdeventparm LIKE tbtcm-eventparm, gdexternalprogramactive LIKE tbtcm-xpgactive, gdjobcount LIKE tbtcm-jobcount, gdjobname LIKE tbtcm-jobname, gdstepcount LIKE tbtcm-stepcount, gderror TYPE sy-subrc, gdreciever TYPE sy-subrc. DATA: wrecsize TYPE i. DATA: gdsubject LIKE sodocchgi1-objdescr, itmessbod LIKE solisti1 OCCURS 0 WITH HEADER LINE, itmessatt LIKE solisti1 OCCURS 0 WITH HEADER LINE, gdsendertype LIKE soextreci1-adrtyp, gdattachmentdesc TYPE soobjnam, gdattachmentname TYPE soobjdes.
Spool to PDF conversions DATA: gdspoolnr LIKE tsp01-rqident, gddestination LIKE rlgrap-filename, gdbytecount LIKE tst01-dsize, gdbuffer TYPE string. Binary store for PDF DATA: BEGIN OF itpdfoutput OCCURS 0. INCLUDE STRUCTURE tline.
DATA: END OF itpdfoutput. CONSTANTS: cdev LIKE sy-sysid VALUE 'DEV', cno(1) TYPE c VALUE ' ', cdevice(4) TYPE c VALUE 'LOCL'.START-OF-SELECTION.
Write statement to represent report output. Spool request is created. if write statement is executed in background. This could also be an. ALV grid which would be converted to PDF without any extra effort WRITE 'Hello World'. New-page print off. IF sy-batch EQ 'X'.
PERFORM getjobdetails. PERFORM obtainspoolid.
Alternative way could be to submit another program and store spool. id into memory, will be stored in sy-spono.submit ZSPOOLTOPDF2. to sap-spool. spool parameters%print. archive parameters%print. without spool dynpro. and return.
Get spool id from program called above. IMPORT wspoolnr FROM MEMORY ID 'SPOOLTOPDF'. PERFORM convertspooltopdf. Security motion detector. PERFORM processemail.
If pdelspl EQ 'X'. PERFORM deletespool. IF sy-sysid = cdev. Wait up to 5 seconds. SUBMIT rsconn01 WITH mode = 'INT' WITH output = 'X' AND RETURN. WRITE:/ 'Program must be executed in background in-order for spool', 'request to be created.' .-.
FORM obtainspoolid.-. FORM obtainspoolid. CHECK NOT ( gdjobname IS INITIAL ).
Sap Spool Is Full
CHECK NOT ( gdjobcount IS INITIAL ). SELECT. FROM tbtcp INTO TABLE ittbtcp WHERE jobname = gdjobname AND jobcount = gdjobcount AND stepcount = gdstepcount AND listident ' ORDER BY jobname jobcount stepcount. READ TABLE ittbtcp INTO watbtcp INDEX 1. IF sy-subrc = 0. Message s004(zdd) with gdspoolnr.
Gdspoolnr = watbtcp-listident. MESSAGE s004(zdd) WITH gdspoolnr. MESSAGE s005(zdd).-. FORM getjobdetails.-.
FORM getjobdetails. Get current job details CALL FUNCTION 'GETJOBRUNTIMEINFO' IMPORTING eventid = gdeventid eventparm = gdeventparm externalprogramactive = gdexternalprogramactive jobcount = gdjobcount jobname = gdjobname stepcount = gdstepcount EXCEPTIONS noruntimeinfo = 1 OTHERS = 2.-. FORM convertspooltopdf.-.
FORM convertspooltopdf. CALL FUNCTION 'CONVERTABAPSPOOLJOB2PDF' EXPORTING srcspoolid = gdspoolnr nodialog = cno dstdevice = cdevice IMPORTING pdfbytecount = gdbytecount TABLES pdf = itpdfoutput EXCEPTIONS errnoabapspooljob = 1 errnospooljob = 2 errnopermission = 3 errconvnotpossible = 4 errbaddestdevice = 5 usercancelled = 6 errspoolerror = 7 errtemseerror = 8 errbtcjobopenfailed = 9 errbtcjobsubmitfailed = 10 errbtcjobclosefailed = 11 OTHERS = 12. CHECK sy-subrc = 0. Transfer the 132-long strings to 255-long strings LOOP AT itpdfoutput. TRANSLATE itpdfoutput USING ' '. CONCATENATE gdbuffer itpdfoutput INTO gdbuffer.
TRANSLATE gdbuffer USING ' '. Itmessatt = gdbuffer. APPEND itmessatt. SHIFT gdbuffer LEFT BY 255 PLACES. IF gdbuffer IS INITIAL.-. FORM processemail.-. FORM processemail.
DESCRIBE TABLE itmessatt LINES gdrecsize. CHECK gdrecsize 0. PERFORM sendemail USING pemail1.
perform sendemail using pemail2.-. FORM sendemail.-. pemail.-. FORM sendemail USING pemail. CHECK NOT ( pemail IS INITIAL ). REFRESH itmessbod. Default subject matter gdsubject = 'Subject'.
Gdattachmentdesc = 'Attachname'. CONCATENATE 'attachname' ' ' INTO gdattachmentname. Itmessbod = 'Message Body text, line 1'. APPEND itmessbod.
Itmessbod = 'Message Body text, line 2.' APPEND itmessbod. If no sender specified - default blank IF psender EQ space.
Gdsendertype = space. Gdsendertype = 'INT'.
Send file by email as.xls speadsheet PERFORM sendfileasemailattachment tables itmessbod itmessatt using pemail 'Example.xls documnet attachment' 'PDF' gdattachmentname gdattachmentdesc psender gdsendertype changing gderror gdreciever.-. FORM deletespool.-. FORM deletespool. DATA: ldspoolnr TYPE tsp01sp0r-rqidchar. Ldspoolnr = gdspoolnr.
CHECK pdelspl cno. CALL FUNCTION 'RSPORRDELETESPOOLREQ' EXPORTING spoolid = ldspoolnr.&-.& Form SENDFILEASEMAILATTACHMENT.&-. Send email.-.
FORM sendfileasemailattachment tables itmessage itattach using pemail pmtitle pformat pfilename pattdescription psenderaddress psenderaddrestype changing perror preciever. DATA: lderror TYPE sy-subrc, ldreciever TYPE sy-subrc, ldmtitle LIKE sodocchgi1-objdescr, ldemail LIKE somlreci1-receiver, ldformat TYPE soobjtp, ldattdescription TYPE soobjnam, ldattfilename TYPE soobjdes, ldsenderaddress LIKE soextreci1-receiver, ldsenderaddresstype LIKE soextreci1-adrtyp, ldreceiver LIKE sy-subrc. Data: tpackinglist like sopcklsti1 occurs 0 with header line, tcontents like solisti1 occurs 0 with header line, treceivers like somlreci1 occurs 0 with header line, tattachment like solisti1 occurs 0 with header line, tobjectheader like solisti1 occurs 0 with header line, wcnt type i, wsentall(1) type c, wdocdata like sodocchgi1. Ldemail = pemail. Ldmtitle = pmtitle. Ldformat = pformat. Ldattdescription = pattdescription.
Ldattfilename = pfilename. Ldsenderaddress = psenderaddress.
Ldsenderaddresstype = psenderaddrestype. Fill the document data. Wdocdata-docsize = 1. Populate the subject/generic message attributes wdocdata-objlangu = sy-langu. Wdocdata-objname = 'SAPRPT'. Wdocdata-objdescr = ldmtitle.
Wdocdata-sensitivty = 'F'. Fill the document data and get size of attachment CLEAR wdocdata. READ TABLE itattach INDEX wcnt. Wdocdata-docsize = ( wcnt - 1 ).
255 + STRLEN( itattach ). Wdocdata-objlangu = sy-langu.
Wdocdata-objname = 'SAPRPT'. Wdocdata-objdescr = ldmtitle. Wdocdata-sensitivty = 'F'. CLEAR tattachment. REFRESH tattachment. Tattachment = itattach.
Describe the body of the message CLEAR tpackinglist. REFRESH tpackinglist. Tpackinglist-transfbin = space. Tpackinglist-headstart = 1. Tpackinglist-headnum = 0.
Tpackinglist-bodystart = 1. DESCRIBE TABLE itmessage LINES tpackinglist-bodynum. Tpackinglist-doctype = 'RAW'. APPEND tpackinglist.
Create attachment notification tpackinglist-transfbin = 'X'. Tpackinglist-headstart = 1.
Tpackinglist-headnum = 1. Tpackinglist-bodystart = 1. DESCRIBE TABLE tattachment LINES tpackinglist-bodynum. Tpackinglist-doctype = ldformat. Tpackinglist-objdescr = ldattdescription.
Tpackinglist-objname = ldattfilename. Tpackinglist-docsize = tpackinglist-bodynum.
255. APPEND tpackinglist. Add the recipients email address CLEAR treceivers. REFRESH treceivers.
Treceivers-receiver = ldemail. Treceivers-rectype = 'U'. Treceivers-comtype = 'INT'. Treceivers-notifdel = 'X'. Treceivers-notifndel = 'X'. APPEND treceivers.
CALL FUNCTION 'SODOCUMENTSENDAPI1' EXPORTING documentdata = wdocdata putinoutbox = 'X' senderaddress = ldsenderaddress senderaddresstype = ldsenderaddresstype commitwork = 'X' IMPORTING senttoall = wsentall TABLES packinglist = tpackinglist contentsbin = tattachment contentstxt = itmessage receivers = treceivers EXCEPTIONS toomanyreceivers = 1 documentnotsent = 2 documenttypenotexist = 3 operationnoauthorization = 4 parametererror = 5 xerror = 6 enqueueerror = 7 OTHERS = 8. Populate zerror return code lderror = sy-subrc. Populate zreceiver return code LOOP AT treceivers. Ldreceiver = treceivers-retrncode.
It is a very common requirement to have the print output from smartforms or sap scripts saved as a local PDF file in the front end. The different ways in which this can be accomplished are:-. Create a spool request for the print and use the report RSTXPDFT4 to save its content as a PDF file in the frontend. Use ABAP coding to obtain the OTF data of the print and use Function modules CONVERTOTF2PDF, GUIDOWNLOAD (or OOPs Front end services) to convert and save the OTF data as a PDF file in the frontend system. Configure a PDF printer output device in SPAD and maintain corresponding FILE printer in the front end systems.
Print outputs can be routed to this output device for saving the print output as PDF file in the frontend system. In this document we will be dwelving into the third option mentioned above which is the simplest way of meeting the requirement. SAP notes associated with this option are:-. 317851: Creating PDF format via spooler in 4.6C/4.6B/4.5B. 576973: Creating a file printer on a Windows PC.
323736: Restrictions with “PDF print” through spooler What is a FILE printer: Printers that use the FILE port(instead of LPT1, COM1 etc) can be added to the frontend system. These printers can be used for saving the print output as a local file. Click the “Add printer” task in the “Printers and Faxes” folder to start the Add printer wizard and add a new FILE printer as per the screenshots below:- Configuring the PDF printer in SPAD transaction. SAP printing process basically involves the spool work process transferring the output data to a host spool system (operating system spooler) which in turn prints the output on the printer attached to it. There are various combinations(printing method) for this depending on where the host spool system resides.
SAPLPD is the transfer program which accepts print data and forwards it to the host spooler on Microsoft Windows platforms. Host spooler in the frontend system is used for downloading PDF files.
Add a new output device using the SPAD transaction with device type set to PDF1. Other device types maybe required for PDF files containing characters from languages like chinese, arabic etc. Create an output device as shown in the screenshots below. In this case “PDFprinter” value is maintained in “Host printer” field of the access method tab since the FILE printer we just created was named so. If this FILE printer has been set as the default printer in the frontend system then value “DEFAULT” can be maintained in this field irrespective of the name given to the printer.
Hereafter, for saving print outputs as PDF file, in the print dialog select the output device ZPDF and click print. This will invoke the SAPLPD program and prompt for a file name for saving the file.
Enter the filename with full path and click ok to save the pdf file in the mentioned path.