04-28-2005 9:06 PM
Hello,
I am trying to merge 2(or more) spools into a single PDF document. Is this possible? If all you have are 2 spools numbers, any ideas how it can be done?
Regards
Cerish
04-29-2005 7:08 AM
Hi,
Try CONVERT_ABAPSPOOLJOB_2_PDF for converting abap spool output to PDF.
Rgds,
J.Jayanthi
04-29-2005 4:38 AM
Hi Cerish,
You can't combine two spool requests into a single PDF file.But you cconvert two different PDF files and attach them in a email and send it to the concerned person.I hope this will sovle your problem.
Regards
Elini.P
04-29-2005 2:36 PM
Hello,
Actually what we want to do is grab the spools and convert them to PDF and then do a mime-download in an IAC to display on the client browser. If we are trying 20 spools then there would be 20 individual PDF documents and 20 popup windows at the client session. That is why we need to find a way to create a single pdf file no matter how many spools we have.
The spools are OTF. So if we can get the content of the spool as an OTF table, I think we can append the OTF tables together after deleting the last EOF line on each. Then we can convert this OTF to PDF. But I havent figured out how to get the OTF internal table given a Spool No. Any ideas? Does anybody think this will work?
Regards
Cerish
04-29-2005 3:00 PM
Hi Cerish,
This looks doable, but perhaps not straightforward.
The abap program RSTXPDF4 (called from FM CONVERT_OTFSPOOLJOB_2_PDF) has the code which performs the conversion for one OTF. At one point it gathers the OTF data into an internal table. If you can figure out the content of the OTF, then you may be able to manipulate it such that you can strip out the EOF stuff and append another OTF internal table (perhaps you will also need to update the TOC - remember I said not straightforward!!).
I guess the first step would be to make a z version of RSTXPDF4 and then just play with appending one spool file OTF twice (before going into all the detailed code of accessing temse yourself).
I don't envy the challenge, but perhaps rewarding if you nail it.
BTW - this is a 5 minute analysis, it may be not as challenging as it appears to me know.
Brad
12-19-2007 11:41 AM
As per ur answer, How to delete the last EOF line on each. for combining sevaral spools into a single PDF file
01-27-2010 10:19 PM
Hello everyone
I know that this post has been done long time ago but I have a similar request but this time it is PDF that are into the spool.
Let me explain.
We have an output type used to print shipping labels in PDF format.
The output type is driven by the handling unit.
So there is one spoolID per handling unit.
Because we can have several handling unit per deliveries, we will have several spoolid containing one label per handling unit.
Now, I need to concatenate all those pdf files, stored into different SpoolIDs, into only one PDF.
I know how to retreive the PDF from a spoolids but I don't know how to merge all those individual PDF into one.
I am using the function FPCOMP_CREATE_PDF_FROM_SPOOL to retrieve the PDF from the spool ID.
Now that I have all those individual PDF, how can I merge them in only one?
The goal is to have on PDF to attach to an email instead several. That can be over 100.
any suggestion will be highly appreciated.
Regards
dstj
04-09-2010 8:27 PM
Any solution..I have the same kind of situation where I want to merge multiple spools into single pdf after retrieveing spool data using FPCOMP_CREATE_PDF_FROM_SPOOL.
I then used SCMS_XSTRING_TO_BINARY to convert to binary and am downloading to pdf but at any time the files are getting replaced and not appended.
Thanks,
ST
05-28-2010 4:45 PM
To merge your spools from SAP to one pdf i have the ultimate solution. Say me if you have again this problem and i will show you how to do it simply.
05-28-2010 7:38 PM
Celian, why don't you tell him? And we would be all very happy to know too!
05-31-2010 9:15 AM
Because my solution use a software and i don't fancy people believe i am advertisind a product !
I said "ultimate" because this soft can fix your problem very quickly but it's not a solution programing directly on SAP ...
However since you ask me to tell more, I am going to do it. My solution use a software of electronic documents management. In order to make final documents this soft read your spools inside the outputdevice. So as concerning your situation, the software pick up throught the outputdevice datas from all spools, reorganize these datas and make a final document. With this soft, it's easy to edit a pdf from several spools.
If you are interested to know more about this software, ask me and i will give you more informations.
11-15-2010 4:58 PM
same issue from my side. Need to merge PDF spoolls into a single one.
How can i get this ultimate solution ?
11-18-2010 6:50 AM
Hello,
I too have a similar requirement. Could you please let me know how to merge individual PDF into single PDF.
I am using the function FPCOMP_CREATE_PDF_FROM_SPOOL to retrieve the Single PDF from the spool ID.
Now, I want to know how to Concatenate these individual PDF into Single PDF File and stored in the application server.
The goal is to have one PDF file in the application server.
Any suggestion will be highly appreciated.
Regards,
Usha
02-04-2011 3:55 PM
Hi,
I used have the same type of issue.I converted the each spool to OTF and then OTF to Binary or Xstring.
After that you can send it as an attachment or open in browser.I think everybody is clear about the process.
Here is the code:
LOOP AT T_SPL_PDF INTO LW_SPONO.
CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
EXPORTING
RQIDENT = LW_SPONO
TABLES
BUFFER = T_PDF
EXCEPTIONS
NO_SUCH_JOB = 1
JOB_CONTAINS_NO_DATA = 2
SELECTION_EMPTY = 3
NO_PERMISSION = 4
CAN_NOT_ACCESS = 5
READ_ERROR = 6
TYPE_NO_MATCH = 7
OTHERS = 8.
IF SY-SUBRC = 0.
ENDIF.
DESCRIBE TABLE T_PDF LINES LW_LINES.
READ TABLE T_PDF INDEX LW_LINES INTO EOF.
DELETE T_PDF INDEX LW_LINES.
APPEND LINES OF T_PDF TO T_FNL_PDF.
APPEND EOF TO T_FNL_PDF.
ENDLOOP.
data OTF TYPE TABLE OF ITCOO.
data SIZE type i.
LOOP AT T_FNL_PDF INTO WA_PDF.
APPEND WA_PDF to OTF.
clear wa_pdf.
ENDLOOP.
DATA LW_STR2XSTR type string.
DATA W_STR2XSTR type string.
DATA W_XSTR type xstring.
data lw_length type i.
call function 'CONVERT_OTF'
exporting
format = 'PDF'
MAX_LINEWIDTH = 132
ARCHIVE_INDEX = ' '
COPYNUMBER = 0
importing
bin_filesize = LW_LENGTH
bin_file = W_XSTR
tables
otf = OTF
lines = T_PDF2XSTR
exceptions
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
others = 5.
LOOP AT T_PDF2XSTR INTO LW_STR2XSTR.
CONCATENATE W_STR2XSTR LW_STR2XSTR INTO W_STR2XSTR.
ENDLOOP.
**********************Enable this code if you want to download to PC and see the output********************
*CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE = size
filename = 'c:\temp\inv.pdf'
FILETYPE = 'BIN'
tables
data_tab = T_PDF2XSTR.
****************************************************************************
*lw_length = xstrlen( w_xstr ).
*******************This code is to delete the spools*****************
LOOP AT T_SPL_PDF INTO LW_SPONO.
lw_spoolid = lw_spono.
CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
EXPORTING
spoolid = lw_SPOOLID.
CLEAR LW_SPONO.
ENDLOOP.
*************************The below code for opening in a BSP application*********************************
Set the file content type in HTTP Response Object
runtime->server->response->set_header_field(
name = if_http_header_fields=>content_type
value = c_mime_type ).
Delete HTTP header attributes that are not required
runtime->server->response->delete_header_field( name = if_http_header_fields=>cache_control ).
runtime->server->response->delete_header_field( name = if_http_header_fields=>expires ).
runtime->server->response->delete_header_field( name = if_http_header_fields=>pragma ).
Set the content disposition as per the mime content
runtime->server->response->set_header_field(
name = if_http_header_fields=>Content_Disposition
value = lw_attachment ).
Set the file data (XSTRING) in HTTP Response Object
runtime->server->response->set_data( data = W_XSTR
length = LW_LENGTH ).
navigation->response_complete( ). "sign
Enjoy!
04-29-2005 7:08 AM
Hi,
Try CONVERT_ABAPSPOOLJOB_2_PDF for converting abap spool output to PDF.
Rgds,
J.Jayanthi
04-29-2005 3:46 PM
Hello Cerish.
Have a lock on FM RSPO_RETURN_ABAP_SPOOLJOB, FM RSPO_SR_OPEN and FM RSPO_SR_WRITE.
The first one extracts lines from a spool request. The second one creates a new spool request. The last one write lines into a spool request.
I used these to three to split up huge request into several small requests ...
And after merging your spool requests into one you can convert it to PDF...
04-29-2005 4:47 PM
Hello,
Thanks for all your help. Putting together the different ideas that popped up I have managed to find a solution. Here is the test report I wrote. This code only works for OTF spools, it does not work on ABAP spools.
report Ztest line-size 80.
parameters:
spool1 like tsp01-rqident,
spool2 like tsp01-rqident,
p_file type localfile default 'C:\file.pdf'.
data:
eof type soli,
tab1 type table of soli,
tab2 type table of soli,
tab type table of soli with header line,
otf type table of itcoo with header line,
doc like table of docs,
pdf like table of tline,
file type string,
size type i,
lines type i.
file = p_file.
call function 'RSPO_RETURN_SPOOLJOB'
exporting
rqident = spool1
tables
buffer = tab1
exceptions
no_such_job = 1
job_contains_no_data = 2
selection_empty = 3
no_permission = 4
can_not_access = 5
read_error = 6
type_no_match = 7
others = 8.
if sy-subrc = 0.
endif.
describe table tab1 lines lines.
read table tab1 index lines into eof.
delete tab1 index lines.
call function 'RSPO_RETURN_SPOOLJOB'
exporting
rqident = spool2
tables
buffer = tab2
exceptions
no_such_job = 1
job_contains_no_data = 2
selection_empty = 3
no_permission = 4
can_not_access = 5
read_error = 6
type_no_match = 7
others = 8.
if sy-subrc <> 0.
write sy-subrc.
endif.
describe table tab2 lines lines.
delete tab2 index lines.
refresh tab.
append lines of tab1 to tab.
append lines of tab2 to tab.
append eof to tab.
loop at tab.
clear otf.
otf = tab.
append otf.
endloop.
call function 'CONVERT_OTF_2_PDF'
exporting
use_otf_mc_cmd = 'X'
importing
bin_filesize = size
tables
otf = otf
doctab_archive = doc
lines = pdf
exceptions
err_conv_not_possible = 1
err_otf_mc_noendmarker = 2
others = 3.
if sy-subrc <> 0.
write sy-subrc.
endif.
call method cl_gui_frontend_services=>gui_download
exporting
filename = file
filetype = 'BIN'
changing
data_tab = pdf
exceptions
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
not_supported_by_gui = 22
error_no_gui = 23
others = 24.
if sy-subrc <> 0.
write sy-subrc.
endif.
Thanks
Cerish
04-29-2005 5:00 PM
Hello Cerish.
Be aware of using FM RSPO_RETURN_SPOOLJOB w/o specifiyng the importing parameters LAST_LINE and FIRST_LINE.
I called RSPO_RETURN_SPOOLJOB within a LOOP and processed line ranges of about 100000 lines with each run. Because the resulting ITABS can get REALLY big!!
04-29-2005 5:16 PM
04-29-2005 5:39 PM
Good point. I has not thought of that. I will do as you suggested.
Thanks
05-12-2006 8:53 PM
I did same thing for a porject . merge 2 abap spool to one pdf . hope it would helpful .
REPORT rstxpdft4 LINE-SIZE 200.
DATA: t_tsp01 LIKE tsp01 OCCURS 100 WITH HEADER LINE .
PARAMETERS:
spool1 LIKE tsp01-rqident,
spool2 LIKE tsp01-rqident,
p_file TYPE localfile DEFAULT 'C:\file.pdf'.
DATA:
eof TYPE soli,
tab1 TYPE TABLE OF soli,
tab2 TYPE TABLE OF soli,
tab TYPE TABLE OF soli WITH HEADER LINE,
otf TYPE TABLE OF itcoo WITH HEADER LINE,
doc LIKE TABLE OF docs,
pdf1 LIKE TABLE OF tline,
file TYPE string,
size TYPE i,
lines TYPE i.
DATA: w_spld TYPE usr01-spld.
DATA PDF LIKE TLINE OCCURS 100 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.
file = p_file.
CALL FUNCTION 'RSPO_RETURN_ABAP_SPOOLJOB'
EXPORTING
rqident = spool1
TABLES
buffer = tab1
EXCEPTIONS
no_such_job = 1
job_contains_no_data = 2
selection_empty = 3
no_permission = 4
can_not_access = 5
read_error = 6
type_no_match = 7
OTHERS = 8.
IF sy-subrc = 0.
ENDIF.
DESCRIBE TABLE tab1 LINES lines.
*READ TABLE tab1 INDEX lines INTO eof.
*DELETE tab1 INDEX lines.
CALL FUNCTION 'RSPO_RETURN_ABAP_SPOOLJOB'
EXPORTING
rqident = spool2
TABLES
buffer = tab2
EXCEPTIONS
no_such_job = 1
job_contains_no_data = 2
selection_empty = 3
no_permission = 4
can_not_access = 5
read_error = 6
type_no_match = 7
OTHERS = 8.
IF sy-subrc <> 0.
WRITE sy-subrc.
ENDIF.
*DESCRIBE TABLE tab2 LINES lines.
*DELETE tab2 INDEX lines.
REFRESH tab.
APPEND LINES OF tab1 TO tab.
clear tab .
do 6 times .
append tab .
enddo.
APPEND LINES OF tab2 TO tab.
*APPEND eof TO tab.
*LOOP AT tab.
CLEAR otf.
otf = tab.
APPEND otf.
*ENDLOOP.
OUTPUT SPOOL MERGERED REPORT
DATA: params LIKE pri_params,
arparams LIKE arc_params,
days(1) TYPE n VALUE 2,
count(3) TYPE n VALUE 1,
valid TYPE c.
SELECT SINGLE spld INTO w_spld FROM usr01 WHERE bname = sy-uname.
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING destination = w_spld " 'LT50'
copies = 1
list_name = 'TEST'
list_text = 'Test NEW-PAGE PRINT ON'
immediately = ' '
release = ' '
new_list_id = 'X'
expiration = days
line_size = 255
line_count = 65
LAYOUT = 'X_PAPER'
SAP_COVER_PAGE = 'X'
RECEIVER = 'SAP*'
DEPARTMENT = 'System'
SAP_OBJECT = 'RS'
AR_OBJECT = 'TEST'
ARCHIVE_ID = 'XX'
ARCHIVE_INFO = 'III'
ARCHIVE_TEXT = 'Description'
NO_DIALOG = ' '
IMPORTING out_parameters = params
out_archive_parameters = arparams
valid = valid.
NEW-PAGE PRINT ON
NEW-SECTION
PARAMETERS params
ARCHIVE PARAMETERS arparams
NO DIALOG.
LOOP AT tab .
WRITE / tab .
ENDLOOP .
NEW-PAGE PRINT OFF .
SELECT * INTO TABLE t_tsp01 FROM tsp01
WHERE rqowner = sy-uname
AND rq2name = 'TEST' .
IF sy-subrc = 0 .
sort t_tsp01 by rqident DESCENDING .
ENDIF .
read table t_tsp01 index 1 .
while numbytes = 0 .
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
SRC_SPOOLID = t_tsp01-rqident "spoolno
NO_DIALOG = ' '
DST_DEVICE =
PDF_DESTINATION =
IMPORTING
PDF_BYTECOUNT = numbytes
PDF_SPOOLID = pdfspoolid
LIST_PAGECOUNT =
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.
ENDWHILE.
CALL FUNCTION 'DOWNLOAD'
EXPORTING
bin_filesize = numbytes
filename = p_file
filetype = 'BIN'
IMPORTING
act_filename = p_file
filesize = numbytes
cancel = cancel
TABLES
data_tab = pdf.
05-13-2006 7:36 AM
Hai Cerish
Go through the following COde
Print any spool file from SAP in PDF format. Can be viewed/edited by using Acrobat. You need the full version of Acrobat to edit, but can view and print using the free version. This is a very simple but useful program and needs to be built on to make it into a real handy tool (put in your own code and change the SAPScript before downloading into PDF format).
-
report ZPDFPRNT no standard page heading.
TABLES: TST05.
DATA: BEGIN OF ITAB OCCURS 0,
TLINE(255),
END OF ITAB.
DATA: BEGIN OF ITAB2 OCCURS 0,
TLINE(255),
END OF ITAB2.
DATA: BEGIN OF ITAB3 OCCURS 0,
TLINE(255),
END OF ITAB3.
DATA: BEGIN OF OTF_TAB OCCURS 0,
TLINE(255),
END OF OTF_TAB.
DATA: LEN_OUT LIKE SOOD-OBJLEN.
DATA: LEN_IN LIKE SOOD-OBJLEN.
DATA: BEGIN OF DATA_SET OCCURS 200,
DATA_LENGTH(5),
PRECOL(1),
DATA_LINE(1000),
END OF DATA_SET.
DATA: BEGIN OF OTF_PAGE OCCURS 200.
INCLUDE STRUCTURE ITCOO.
DATA: END OF OTF_PAGE,
OTF_PAGES TYPE P,
OTF_MAX_PAGES TYPE P VALUE 10.
DATA: BEGIN OF OTF_CONTROL.
INCLUDE STRUCTURE ITCPP.
DATA: END OF OTF_CONTROL,
FORCE_RAW_OTF VALUE ' ',
L100_EXCLUDE(4) VALUE 'OTFJ',
BEGIN OF OTF_PAGE_INDEX OCCURS 20,
LINE_NUM TYPE P,
END OF OTF_PAGE_INDEX,
CUR_OTF_PAGE VALUE 1.
DATA: DATA_SET_LINECOUNT TYPE P,
DATA_SET_MAX_LINES TYPE P VALUE 100000,
DATA_SET_VALID TYPE C VALUE ' ',
DATA_SET_IS_OTF TYPE C VALUE ' ',
DATA_SET_LENGTH(5) TYPE C,
LINE_SPECIAL LIKE DATA_SET-DATA_LINE,
NEED_LINE_SPECIAL TYPE C,
DSN_TYPE(8) TYPE C.
DATA: FCODE(4) TYPE C,
DATE TYPE D,
TIME TYPE T,
RC(10) TYPE C,
ERRMSG(100) TYPE C,
PRINTJOB_CREATED(1) TYPE C,
PRINTJOB_CLEARED(1) TYPE C,
PRINTJOB_LIST(1) TYPE C,
DISPLAY_MODE(1) TYPE C,
LINE_MAX TYPE P VALUE '100000',
NEW_SCREEN_300(1) TYPE C,
MULTI_PRINT_300(1) TYPE C,
PRINT_ALL_300(1) TYPE C,
PRINT_COUNT_300 TYPE I,
SHOW_USER_100 TYPE C VALUE ' ',
ERROR_DISPLAY_LEVEL TYPE C VALUE '9',
NEXT_ERROR_DISPLAY_LEVEL TYPE C,
PREV_ERROR_DISPLAY_LEVEL TYPE C,
START_300(5) TYPE C, END_300(5) TYPE C,
SEP LIKE SY-VLINE,
DEFAULT_PRI,
TSP01_BUF LIKE TSP01,
TSP01_CURLINE LIKE SY-STARO,
TSP01_CURCOL LIKE SY-CUCOL,
TSP01_CURROW LIKE SY-CUROW.
DATA: BEGIN OF DATA_SET_LINE,
DATA_LENGTH(5),
PRECOL(1),
DATA_LINE(1000),
END OF DATA_SET_LINE.
DATA: STATUS LIKE SY-SUBRC.
DATA: WGF_MESSAGE(80).
DATA: H_PATH(20) TYPE C.
DATA: H_MASK(20) TYPE C VALUE ',.pdf ,.pdf. '.
DATA: FILE_NAME(20).
DATA: FILENAME LIKE RLGRAP-FILENAME.
DATA: IMPORT(132).
PARAMETERS: IDENT(5) TYPE C.
PERFORM GET_OTF_TAB.
LOOP AT OTF_PAGE.
OTF_TAB-TLINE = OTF_PAGE.
APPEND OTF_TAB.
ENDLOOP.
CALL FUNCTION 'SX_OBJECT_CONVERT_OTF_PDF'
EXPORTING
FORMAT_SRC = 'OTF'
FORMAT_DST = 'PDF'
DEVTYPE = 'ASCIIPRI'
LEN_IN = LEN_IN
IMPORTING
LEN_OUT = LEN_OUT
TABLES
CONTENT_IN = OTF_TAB
CONTENT_OUT = ITAB2
EXCEPTIONS
ERR_CONV_FAILED = 1
OTHERS = 2.
PERFORM GET_PATH USING 'PDF_FILE'.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
FILENAME = FILENAME
FILETYPE = 'BIN'
BIN_FILESIZE = LEN_OUT
TABLES
DATA_TAB = ITAB2
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.
&----
*& Form GET_OTF_TAB
&----
FORM GET_OTF_TAB.
DATA: PART(4) VALUE '0001',
BEGIN OF MSG,
A(40),
B(40),
C(40),
END OF MSG.
REFRESH DATA_SET.
DATA_SET_LINECOUNT = 0.
DATA_SET_IS_OTF = ' '.
OTF_PAGES = 0.
REFRESH OTF_PAGE_INDEX.
CALL 'RSPOACSD'.
SELECT * FROM TST05 WHERE DTHREAD = 'X'.
CALL 'RSPOAOSD'
ID 'ID' FIELD IDENT
ID 'TYPE' FIELD TST05-DTYPE
ID 'RECTYP' FIELD 'VYL----'
ID 'RC' FIELD RC
ID 'ERRMSG' FIELD ERRMSG.
STATUS = SY-SUBRC.
IF STATUS = 0.
DSN_TYPE = TST05-DTYPE.
IF DSN_TYPE(3) = 'OTF'.
DATA_SET_IS_OTF = 'X'.
ENDIF.
ENDIF.
IF STATUS <> 24. EXIT. ENDIF.
ENDSELECT.
DATA_SET_VALID = 'X'.
DATA_SET_MAX_LINES = ( LINE_MAX * '1.1' ) + 100.
DO.
CLEAR: DATA_SET_LINE, DATA_SET_LENGTH.
CALL 'RSPOARSD'
ID 'BUFF' FIELD DATA_SET_LINE+5
ID 'DATALEN' FIELD DATA_SET_LENGTH
ID 'RC' FIELD RC
ID 'ERRMSG' FIELD ERRMSG.
STATUS = SY-SUBRC.
IF STATUS = 36.
WHILE STATUS = 36.
CALL 'RSPOACSD'
ID 'RC' FIELD RC
ID 'ERRMSG' FIELD ERRMSG.
ADD 1 TO PART.
IF DATA_SET_IS_OTF = ' '.
CALL 'RSPOAOSD'
ID 'ID' FIELD IDENT
ID 'TYPE' FIELD DSN_TYPE
ID 'PART' FIELD PART
ID 'RECTYP' FIELD 'VYL----'
ID 'RC' FIELD RC
ID 'ERRMSG' FIELD ERRMSG.
ELSE.
CALL 'RSPOAOSD'
ID 'ID' FIELD IDENT
ID 'PART' FIELD PART
ID 'TYPE' FIELD DSN_TYPE
ID 'RECTYP' FIELD 'VYL----'
ID 'RC' FIELD RC
ID 'ERRMSG' FIELD ERRMSG.
ENDIF.
IF SY-SUBRC NE 0. EXIT. ENDIF.
CLEAR: DATA_SET_LINE, DATA_SET_LENGTH.
CALL 'RSPOARSD'
ID 'BUFF' FIELD DATA_SET_LINE+5
ID 'DATALEN' FIELD DATA_SET_LENGTH
ID 'RC' FIELD RC
ID 'ERRMSG' FIELD ERRMSG.
STATUS = SY-SUBRC.
ENDWHILE.
ENDIF.
IF STATUS <> 0 AND STATUS <> 40. EXIT. ENDIF.
DATA_SET = DATA_SET_LINE.
IF NOT ( DATA_SET_LENGTH IS INITIAL ).
DATA_SET-DATA_LENGTH = DATA_SET_LENGTH - 1.
ENDIF.
APPEND DATA_SET.
ADD 1 TO DATA_SET_LINECOUNT.
IF DATA_SET_IS_OTF = ' '.
IF DATA_SET_LINECOUNT >= DATA_SET_MAX_LINES.
CLEAR DATA_SET.
APPEND DATA_SET.
MOVE '----
' TO DATA_SET-DATA_LINE.
APPEND DATA_SET.
CLEAR DATA_SET.
APPEND DATA_SET.
WRITE: 'Abbruch nach'(029) TO MSG-A.
WRITE: DATA_SET_MAX_LINES TO MSG-B.
WRITE: 'Zeilen.'(030) TO MSG-C.
CONDENSE MSG.
DATA_SET-DATA_LINE = MSG.
APPEND DATA_SET.
EXIT.
ENDIF.
ELSE.
MOVE DATA_SET_LINE-DATA_LINE TO OTF_PAGE.
APPEND OTF_PAGE.
IF OTF_PAGE(2) = 'EP'.
ADD 1 TO OTF_PAGES.
IF OTF_PAGES >= OTF_MAX_PAGES.
MESSAGE S229(PO) WITH OTF_MAX_PAGES.
EXIT.
ENDIF.
ELSEIF OTF_PAGE(2) = 'OP'.
OTF_PAGE_INDEX-LINE_NUM = DATA_SET_LINECOUNT.
APPEND OTF_PAGE_INDEX.
ENDIF.
ENDIF.
ENDDO.
IF STATUS <> 0 AND STATUS <> 12.
CALL 'RSPOACSD'.
MESSAGE E112(PO) WITH STATUS RC ERRMSG.
ENDIF.
CALL 'RSPOACSD'.
STATUS = SY-SUBRC.
IF STATUS <> 0.
MESSAGE E112(PO) WITH STATUS RC ERRMSG.
ENDIF.
ENDFORM. " GET_OTF_TAB
&----
*& Form GET_PATH
&----
FORM GET_PATH USING P_FILENAME.
CLEAR: H_PATH, FILE_NAME.
FILE_NAME = P_FILENAME.
CALL FUNCTION 'WS_QUERY'
EXPORTING
QUERY = 'CD' "// Current Directory
IMPORTING
RETURN = H_PATH.
CONCATENATE FILE_NAME '.pdf' INTO FILE_NAME.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
DEF_FILENAME = FILE_NAME
DEF_PATH = H_PATH
MASK = H_MASK
MODE = 'O'
IMPORTING
FILENAME = FILENAME"dbname
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS = 5.
ENDFORM. " GET_PATH
-
2)
This report takes another report as input, and captures the output of that report. The output is then converted to
PDF and saved to a local file. This shows how to use some of the PDF function modules, as well as an easy way to
create PDF files.
Source Code Listing
report zabap_2_pdf.
*-- Enhancements: only allow to be run with variant. Then called
*-- program will be transparent to users
*-- TABLES
tables:
tsp01.
*-- STRUCTURES
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.
*-- INTERNAL TABLES
data:
mtab_pdf like tline occurs 0 with header line,
mc_filename 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 'X_65_132'. " Paper Format
start-of-selection.
concatenate 'c:\'
p_repid
'.pdf'
into mc_filename.
*-- Setup the Print Parmaters
call function 'GET_PRINT_PARAMETERS'
exporting
authority= space
copies = '1'
cover_page = space
data_set = space
department = space
destination = space
expiration = '1'
immediately = space
in_archive_parameters = space
in_parameters = space
layout = space
mode = space
new_list_id = 'X'
no_dialog= 'X'
user = sy-uname
importing
out_parameters = mstr_print_parms
valid = mc_valid
exceptions
archive_info_not_found = 1
invalid_print_params = 2
invalid_archive_params = 3
others = 4.
*-- Make sure that a printer destination has been set up
*-- If this is not done the PDF function module ABENDS
if mstr_print_parms-pdest = space.
mstr_print_parms-pdest = 'LOCL'.
endif.
*-- Explicitly set line width, and output format so that
*-- the PDF conversion comes out OK
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
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
others = 12.
call function 'DOWNLOAD'
exporting
bin_filesize = mi_bytecount
filename = mc_filename
filetype = 'BIN'
importing
act_filename = mc_filename
tables
data_tab = mtab_pdf.
----
FORM get_spool_number *
----
Get the most recent spool created by user/report *
----
--> F_REPID *
--> F_UNAME *
--> F_RQIDENT *
----
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
Thanks & Regards
Sreenivasulu P
Message was edited by: Sreenivasulu Ponnadi
06-03-2006 3:25 PM
Has anyone had to deal with attaching a Spool to PDF AND a PDF file pulled from the file server. In other words, 2 PDF's attachments in one email being sent?
I am not sure if merging these 2 PDF's into one PDF is possible or if sending 2 PDF's in one email.
Has anyone come across this?
01-28-2010 4:08 AM
Hi,
This wiki will surely help you:
https://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=134545580
Thanks,
Krishna
01-29-2010 6:30 PM
Krishna,
Your solution does not work when the spool is already the PDF type. If it the PDF Spool Request has more than 1 page, each page will be one .COA file locate in the server /usr/sap/DEV/SYS/global directory.
Any other suggestions?
Thanks, -Khai-
04-30-2013 10:13 PM
The following report, takes already existing pdf spools, and creates a new one with consolidated pdfs in a single spool.
REPORT zovg_single_spool4.
TYPES:
BEGIN OF ty_tsp01,
rqident TYPE tsp01-rqident,
rqtitle TYPE tsp01-rqtitle,
rqdest TYPE tsp01-rqdest,
ban TYPE c,
END OF ty_tsp01.
CONSTANTS: l_c_printer(8) TYPE c VALUE 'LP0K',
l_c_doctype(4) TYPE c VALUE 'ADSP',
l_c_sptd TYPE c VALUE '/'.
DATA:
l_i_old_spools TYPE TABLE OF ty_tsp01,
l_wa_old_spool TYPE ty_tsp01,
g_v_pdf1 TYPE fpcontent,
l_v_data TYPE fpcontent,
l_v_prdest TYPE tsp01-rqdest,
l_v_handle TYPE sy-tabix,
l_v_spoolid TYPE tsp01-rqident,
l_v_globaldir TYPE text1024,
l_v_pages TYPE i,
l_v_dstfile TYPE text1024,
l_v_filesize TYPE i,
l_v_partname TYPE adspart
.
data: file_list like adsfile occurs 100.
data: file like adsfile.
data: content type xstring.
data: partfilename type rlgrap-filename.
data: l_v_ext(3) type c.
l_v_prdest = l_c_printer.
l_wa_old_spool-rqident = 11485.
APPEND l_wa_old_spool
TO l_i_old_spools.
l_wa_old_spool-rqident = 11486.
APPEND l_wa_old_spool
TO l_i_old_spools.
LOOP AT l_i_old_spools
INTO l_wa_old_spool.
IF l_v_spoolid IS INITIAL.
* Create a new spool order for the PDF'S
CALL FUNCTION 'ADS_SR_OPEN'
EXPORTING
dest = l_v_prdest
append = ' '"append
doctype = l_c_doctype
titleline = 'Title line Test'
IMPORTING
handle = l_v_handle
spoolid = l_v_spoolid
partname = l_v_partname
EXCEPTIONS
device_missing = 1
no_such_device = 2
operation_failed = 3
wrong_doctype = 4
wrong_devicetype = 5
OTHERS = 6.
ELSE.
CALL FUNCTION 'ADS_SR_OPEN'
EXPORTING
dest = l_v_prdest
append = 'X'
doctype = l_c_doctype
usespoolid = l_v_spoolid
IMPORTING
handle = l_v_handle
spoolid = l_v_spoolid
partname = l_v_partname
EXCEPTIONS
device_missing = 1
no_such_device = 2
operation_failed = 3
wrong_doctype = 4
wrong_devicetype = 5
OTHERS = 6.
ENDIF.
CALL FUNCTION 'ADS_GET_PATH'
IMPORTING
ads_path = l_v_globaldir.
CALL FUNCTION 'FPCOMP_CREATE_PDF_FROM_SPOOL'
EXPORTING
i_spoolid = l_wa_old_spool-rqident
i_partnum = 1
IMPORTING
E_PDF = g_v_pdf1
E_RENDERPAGECOUNT = l_v_pages
* E_PDF_FILE =
EXCEPTIONS
ADS_ERROR = 1
USAGE_ERROR = 2
SYSTEM_ERROR = 3
INTERNAL_ERROR = 4
OTHERS = 5
.
l_v_data = g_v_pdf1.
*get list of part files
refresh file_list.
clear: file_list.
call function 'ADS_SR_READ_CONTENT_DIR'
exporting
RQIDENT = l_wa_old_spool-rqident
tables
FILE_LIST = file_list
exceptions
WRONG_DOCTYPE = 1
INTERNAL_ERROR = 2
NO_DIRECTORY = 3
others = 4.
*save every part file
LOOP AT file_list
into file.
partfilename = file-name.
CALL FUNCTION 'TRINT_FILE_GET_EXTENSION'
EXPORTING
filename = partfilename
* UPPERCASE = 'X'
IMPORTING
EXTENSION = l_v_ext
.
call function 'ADS_SR_READ_CONTENT'
exporting
RQIDENT = l_wa_old_spool-rqident
PARTFILENAME = partfilename
importing
CONTENT_BIN = content
exceptions
CANNOT_OPEN_FILE = 1
OPEN_DATASET_NO_AUTHORITY = 2
OPEN_DATASET_TOO_MANY_FILES = 3
OPEN_DATASET_INTERNAL_ERROR = 4
WRONG_DOCTYPE = 5
others = 6.
clear l_v_dstfile.
* * Route to save part file
CONCATENATE l_v_globaldir
l_c_sptd
l_v_partname
'.'
l_v_ext
INTO l_v_dstfile.
OPEN DATASET l_v_dstfile
FOR OUTPUT IN BINARY MODE.
TRANSFER content
TO l_v_dstfile.
CLOSE DATASET l_v_dstfile.
ENDLOOP.
l_v_filesize = xstrlen( l_v_data ).
*confirm partfiles.
*"Add old spool content to new spool
CALL FUNCTION 'ADS_SR_CONFIRM'
EXPORTING
handle = l_v_handle
partname = l_v_partname
size = l_v_filesize
pages = l_v_pages
no_pdf = ' '
EXCEPTIONS
handle_not_valid = 1
operation_failed = 2
OTHERS = 3.
* Close the new spool order
CALL FUNCTION 'ADS_SR_CLOSE'
EXPORTING
handle = l_v_handle
EXCEPTIONS
handle_not_valid = 1
operation_failed = 2
OTHERS = 3.
ENDLOOP.
10-16-2013 1:15 PM
Based on the code of Omar, we have created now a solution to merge ads (pdf) spool files containing several parts (e.g. hrforms payslip) with another ads (pdf) spool file:(e.g. cover)
*&---------------------------------------------------------------------*
*& Form MERGE_SPOOLS
*&---------------------------------------------------------------------*
FORM MERGE_SPOOLS USING i_spool_cover TYPE RSPOID
i_spool_payslip TYPE RSPOID.
DATA: BEGIN OF ls_spool,
rqident TYPE tsp01-rqident,
rqtitle TYPE tsp01-rqtitle,
rqdest TYPE tsp01-rqdest,
ban TYPE c,
END OF ls_spool,
lt_spool LIKE STANDARD TABLE OF ls_spool.
CONSTANTS: lc_printer(8) TYPE c VALUE 'XXXX', " use a PDF printer
lc_doctype(4) TYPE c VALUE 'ADSP',
lc_sptd TYPE c VALUE '/'.
DATA: lf_pdf1 TYPE fpcontent,
lf_prdest TYPE tsp01-rqdest,
lf_handle TYPE sy-tabix,
lf_new_spoolid TYPE tsp01-rqident,
lf_globaldir TYPE text1024,
lf_pages TYPE i,
lf_pages_add TYPE i,
lf_dstfile TYPE text1024,
lf_partname TYPE adspart,
lf_partname1 TYPE adspart,
lf_filenum(5) type n,
lf_filenamlen type i,
lf_title type TSP01-RQTITLE.
data: lt_file_list TYPE TABLE OF adsfile.
data: ls_file like line of lt_file_list.
data: lf_content type xstring.
data: lf_partfilename type rlgrap-filename.
data: lf_ext(3) type c.
DATA: lf_count(5) TYPE N.
DATA: lf_old_count(5) TYPE N,
lf_new_count(5) TYPE N.
DATA: lt_split_old TYPE TABLE OF STRING,
lt_split_new TYPE TABLE OF STRING,
ls_split TYPE STRING.
DATA: lf_partnum TYPE I.
DATA: lf_pddest TYPE SYPDEST.
DATA: lf_list_text TYPE SYPRTXT.
DATA: ls_param_out TYPE pri_params.
DATA: lf_valid(1) TYPE C.
DATA: cnt_parts TYPE I.
DATA: lt_confirm TYPE TABLE OF ADSCONFDESC,
ls_confirm LIKE LINE OF lt_confirm.
* Fill Table with Spoolids, that should be merged
CLEAR: ls_spool.
ls_spool-rqident = i_spool_cover.
APPEND ls_spool TO lt_spool.
CLEAR: ls_spool.
ls_spool-rqident = i_spool_payslip.
APPEND ls_spool TO lt_spool.
* Print Settings
CALL FUNCTION 'GET_PRINT_PARAMETERS'
IMPORTING
OUT_PARAMETERS = ls_param_out
valid = lf_valid
EXCEPTIONS
ARCHIVE_INFO_NOT_FOUND = 1
INVALID_PRINT_PARAMS = 2
INVALID_ARCHIVE_PARAMS = 3
OTHERS = 4.
IF sy-subrc <> 0.
ENDIF.
lf_prdest = ls_param_out-pdest.
lf_title = ls_param_out-prtxt.
* Main Loop
LOOP AT lt_spool INTO ls_spool.
CLEAR: lf_old_count.
ADD 1 TO lf_count.
CLEAR: lt_confirm.
IF lf_new_spoolid IS INITIAL.
* Create New Spoolid, append the 2nd spool
CALL FUNCTION 'ADS_SR_OPEN'
EXPORTING
dest = lf_prdest
append = ' '"append
doctype = lc_doctype
titleline = lf_title
IMPORTING
handle = lf_handle
spoolid = lf_new_spoolid
partname = lf_partname
EXCEPTIONS
device_missing = 1
no_such_device = 2
operation_failed = 3
wrong_doctype = 4
wrong_devicetype = 5
OTHERS = 6.
ELSE.
CALL FUNCTION 'ADS_SR_OPEN'
EXPORTING
dest = lf_prdest
append = 'X'
doctype = lc_doctype
usespoolid = lf_new_spoolid
IMPORTING
handle = lf_handle
spoolid = lf_new_spoolid
partname = lf_partname
EXCEPTIONS
device_missing = 1
no_such_device = 2
operation_failed = 3
wrong_doctype = 4
wrong_devicetype = 5
OTHERS = 6.
ENDIF.
" Get path of physical files
CALL FUNCTION 'ADS_GET_PATH'
IMPORTING
ads_path = lf_globaldir.
" Get file list of spool parts (physical spool)
clear: lt_file_list, ls_file.
CALL FUNCTION 'ADS_SR_READ_CONTENT_DIR'
EXPORTING
RQIDENT = ls_spool-rqident
TABLES
FILE_LIST = lt_file_list
EXCEPTIONS
WRONG_DOCTYPE = 1
INTERNAL_ERROR = 2
NO_DIRECTORY = 3
others = 4.
" Loop at part files
LOOP AT lt_file_list INTO ls_file.
lf_partfilename = ls_file-name.
CALL FUNCTION 'TRINT_FILE_GET_EXTENSION'
EXPORTING
filename = lf_partfilename
UPPERCASE = space
IMPORTING
EXTENSION = lf_ext.
CALL FUNCTION 'ADS_SR_READ_CONTENT'
EXPORTING
RQIDENT = ls_spool-rqident
PARTFILENAME = lf_partfilename
IMPORTING
CONTENT_BIN = lf_content
EXCEPTIONS
CANNOT_OPEN_FILE = 1
OPEN_DATASET_NO_AUTHORITY = 2
OPEN_DATASET_TOO_MANY_FILES = 3
OPEN_DATASET_INTERNAL_ERROR = 4
WRONG_DOCTYPE = 5
others = 6.
clear lf_dstfile.
* Split Partname and build counter for merged parts
* e.g.: SPOOL0000022568_00002
CLEAR: lt_split_new, lt_split_old.
SPLIT lf_partname AT '_' INTO TABLE lt_split_new.
SPLIT lf_partfilename AT '_' INTO TABLE lt_split_old.
LOOP AT lt_split_new INTO ls_split.
EXIT.
ENDLOOP.
lf_partname = ls_split.
LOOP AT lt_split_old INTO ls_split.
ENDLOOP.
IF sy-subrc EQ 0.
REPLACE ALL OCCURRENCES OF lf_ext IN ls_split WITH SPACE.
REPLACE ALL OCCURRENCES OF '.' IN ls_split WITH SPACE.
CONDENSE ls_split NO-GAPS.
lf_new_count = ls_split. "current counter for new spool
IF lf_new_count NE lf_old_count AND NOT lf_old_count IS INITIAL. "at counter change add 1 to new counter
ADD 1 TO lf_count.
ENDIF.
lf_old_count = lf_new_count.
CONCATENATE lf_partname lf_count INTO lf_partname SEPARATED BY '_'.
ENDIF.
lf_partnum = lf_new_count.
CALL FUNCTION 'FPCOMP_CREATE_PDF_FROM_SPOOL'
EXPORTING
i_spoolid = ls_spool-rqident
i_partnum = lf_partnum
IMPORTING
E_PDF = lf_pdf1
E_RENDERPAGECOUNT = lf_pages
* E_PDF_FILE =
EXCEPTIONS
ADS_ERROR = 1
USAGE_ERROR = 2
SYSTEM_ERROR = 3
INTERNAL_ERROR = 4
OTHERS = 5.
* Save physical file on file system
CONCATENATE lf_globaldir
lc_sptd
lf_partname
'.'
lf_ext
INTO lf_dstfile.
OPEN DATASET lf_dstfile
FOR OUTPUT IN BINARY MODE.
TRANSFER lf_content
TO lf_dstfile.
CLOSE DATASET lf_dstfile.
IF lf_ext EQ 'PDF' OR lf_ext EQ 'pdf'.
"Fill table for multi confirm
CLEAR: ls_confirm.
ls_confirm-PARTNAME = lf_partname.
ls_confirm-partsize = xstrlen( lf_content ).
ls_confirm-partpages = lf_pages.
ls_confirm-no_pdf = ' '.
ls_confirm-numberdocs = '1'.
APPEND ls_confirm TO lt_confirm.
ENDIF.
ENDLOOP.
* "Add old spool content to new spool
CALL FUNCTION 'ADS_SR_CONFIRM_MULTI'
EXPORTING
handle = lf_handle
adsconfdesc = lt_confirm
EXCEPTIONS
HANDLE_NOT_VALID = 1
OPERATION_FAILED = 2
OTHERS = 3
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
* Close the new spool order
CALL FUNCTION 'ADS_SR_CLOSE'
EXPORTING
handle = lf_handle
EXCEPTIONS
handle_not_valid = 1
operation_failed = 2
OTHERS = 3.
ENDLOOP.
IF sy-subrc EQ 0.
* Close the new spool order
CALL FUNCTION 'ADS_SR_CLOSE'
EXPORTING
handle = lf_handle
final = 'X'
EXCEPTIONS
handle_not_valid = 1
operation_failed = 2
OTHERS = 3.
ENDIF.
ENDFORM. " MERGE_SPOOLS
09-27-2016 1:33 PM