10-02-2008 10:42 AM
Hi friends, when I run this program I don't get pdf file on my hard drive.
I get spool but then output is not saved in pdf, please look at this code below
What is wrong??
Thanks,
Nihad
REPORT ZABAP2PDF .
tables:
tsp01.
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.
data:v_repid type sy-repid.
v_repid = sy-repid.
data:
mtab_pdf like tline occurs 0 with header line,
mc_filename like rlgrap-filename.
parameters:
p_repid like v_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.
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.
perform get_spool_number
using v_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 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.
10-02-2008 11:24 AM
There may be something in program RSTXPDFT4 that could help troubleshoot...
10-02-2008 11:29 AM
Check the below code for reference.
DATA: PRINT_PARAMETERS TYPE PRI_PARAMS,
VALID_FLAG TYPE C LENGTH 1.
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
IMMEDIATELY = 'X' "C_IMMEDIATELY
*LAYOUT = 'Z_48_144'
*LINE_COUNT = '48'
LINE_SIZE = '255'
*NEW_LIST_ID = C_NEW_LIST_ID
NO_DIALOG = 'X'
RELEASE = 'X'
IMPORTING
OUT_PARAMETERS = PRINT_PARAMETERS
VALID = VALID_FLAG
EXCEPTIONS
ARCHIVE_INFO_NOT_FOUND = 1
INVALID_PRINT_PARAMS = 2
INVALID_ARCHIVE_PARAMS = 3
OTHERS = 4 .
G_PDEST = PRINT_PARAMETERS-PDEST.
NEW-PAGE PRINT ON PARAMETERS PRINT_PARAMETERS
NO DIALOG.
*... Display Summary Report.
FORMAT COLOR COL_HEADING.
WRITE:/1 TEXT-006.
WRITE 😕 SY-ULINE(210).
FORMAT COLOR OFF.
NEW-PAGE PRINT OFF.
NEW-PAGE.
COMMIT WORK.
NEW-PAGE PRINT OFF.
DATA: NUMBYTES TYPE TST01-DSIZE,
PDFSPOOLID TYPE TSP01-RQIDENT.
DATA: BEGIN OF PDFDATA OCCURS 0.
INCLUDE STRUCTURE TLINE.
DATA: END OF PDFDATA.
DATA: G1_LINES_TXT TYPE I.
DATA : L_DOCUMENT_DATA TYPE SODOCCHGI1,
T_PACKING_LIST TYPE STANDARD TABLE OF SOPCKLSTI1,
W_OBJHEAD TYPE SOLI_TAB,
T_OBJBIN TYPE STANDARD TABLE OF SOLISTI1,
T_OBJTXT TYPE STANDARD TABLE OF SOLISTI1,
LW_PACKING_LIST TYPE SOPCKLSTI1,
L_LINES TYPE I,
W_RECEIVER TYPE SOMLRECI1,
T_RECEIVER TYPE STANDARD TABLE OF SOMLRECI1.
DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.
DATA: OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.
DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
DATA: OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.
DATA: DOC_CHNG LIKE SODOCCHGI1.
DATA: TAB_LINES LIKE SY-TABIX.
SELECT MAX( RQIDENT ) INTO G_SPOOL_NUM
FROM TSP01
WHERE RQCLIENT = SY-MANDT AND
RQOWNER = SY-UNAME.
*....Convert Spool to PDF
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
SRC_SPOOLID = G_SPOOL_NUM
NO_DIALOG = 'X'
DST_DEVICE = G_PDEST
IMPORTING
PDF_BYTECOUNT = NUMBYTES
TABLES
PDF = PDFDATA
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.
*...Convert 132 char to 255 char
LOOP AT PDFDATA.
TRANSLATE PDFDATA USING ' ~'.
CONCATENATE GD_BUFFER PDFDATA INTO GD_BUFFER.
ENDLOOP.
TRANSLATE GD_BUFFER USING '~ '.
DO.
IT_MESS_ATT = GD_BUFFER.
APPEND IT_MESS_ATT.
SHIFT GD_BUFFER LEFT BY 255 PLACES.
IF GD_BUFFER IS INITIAL.
EXIT.
ENDIF.
ENDDO.
Creating the document attachment
LOOP AT IT_MESS_ATT.
OBJBIN = IT_MESS_ATT.
APPEND OBJBIN.
CLEAR: OBJBIN,
IT_MESS_ATT.
ENDLOOP.
Creating the document to be sent
DOC_CHNG-OBJ_NAME = 'IG Balance'.
*.....Subject of the email.
CONCATENATE 'Intragroup Confirmation from AoO: ' P_ZAOO INTO DOC_CHNG-OBJ_DESCR.
DOC_CHNG-OBJ_DESCR = 'Intragroup Confirmation from AoO '.
*...Body of the email
OBJTXT = 'Please find attached a summary and details for intragroup transactions for the referenced AoOs.'.
APPEND OBJTXT.
OBJTXT = 'Any queries regarding the attached should be addressed to the contact names on the Summary Report.'.
APPEND OBJTXT.
DESCRIBE TABLE OBJTXT LINES TAB_LINES.
READ TABLE OBJTXT INDEX TAB_LINES.
DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).
Creating the entry for the compressed document
CLEAR OBJPACK-TRANSF_BIN.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 0.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
OBJPACK-DOC_TYPE = 'RAW'.
APPEND OBJPACK.
DESCRIBE TABLE OBJBIN LINES TAB_LINES.
OBJHEAD = 'IG Balace.PDF'. APPEND OBJHEAD.
Creating the entry for the compressed attachment
OBJPACK-TRANSF_BIN = 'X'.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 1.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
OBJPACK-DOC_TYPE = 'PDF'.
OBJPACK-OBJ_NAME = 'ATTACHMENT'.
OBJPACK-OBJ_DESCR = 'IG Balance Report'.
OBJPACK-DOC_SIZE = TAB_LINES * 255.
APPEND OBJPACK..
Entering names in the distribution list
DATA: L_CNT TYPE I.
LOOP AT T_EMAIL INTO W_EMAIL.
IF W_EMAIL-ZCONTACT1 IS NOT INITIAL.
RECLIST-RECEIVER = W_EMAIL-ZCONTACT1.
RECLIST-REC_TYPE = 'U'.
L_CNT = L_CNT + 1.
ELSEIF W_EMAIL-ZCONTACT2 IS NOT INITIAL.
RECLIST-RECEIVER = W_EMAIL-ZCONTACT2.
RECLIST-REC_TYPE = 'U'.
L_CNT = L_CNT + 1.
ENDIF.
APPEND RECLIST.
CLEAR: RECLIST,
W_EMAIL.
ENDLOOP.
SELECT SINGLE ZAOO
ZCONTACT1
ZCONTACT2 FROM ZFI_MT_RPTRMAP INTO W_EMAIL
WHERE ZAOO EQ P_ZAOO.
IF W_EMAIL-ZCONTACT1 IS NOT INITIAL.
RECLIST-RECEIVER = W_EMAIL-ZCONTACT1.
RECLIST-REC_TYPE = 'U'.
L_CNT = L_CNT + 1.
APPEND RECLIST.
ELSEIF W_EMAIL-ZCONTACT2 IS NOT INITIAL.
RECLIST-RECEIVER = W_EMAIL-ZCONTACT2.
RECLIST-REC_TYPE = 'U'.
L_CNT = L_CNT + 1.
APPEND RECLIST.
ENDIF.
IF L_CNT > 0.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = DOC_CHNG
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X'
TABLES
PACKING_LIST = OBJPACK
OBJECT_HEADER = OBJHEAD
CONTENTS_BIN = OBJBIN
CONTENTS_TXT = OBJTXT
RECEIVERS = RECLIST
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
OPERATION_NO_AUTHORIZATION = 4
OTHERS = 99.
CASE SY-SUBRC.
WHEN 0.
WRITE 'Email sent successfully'.
WHEN 1.
WRITE: / 'no authorization to send to the specified number of recipients!'.
WHEN 2.
WRITE: / 'document could not be sent to any of the recipients!'.
WHEN 4.
WRITE: / 'no authorization to send !'.
WHEN OTHERS.
WRITE: / 'error occurred during sending !'.
ENDCASE.
ELSE.
MESSAGE S000 WITH TEXT-018.
STOP.
ENDIF.
*...Delete Spool Request.
DATA: SPOOLID TYPE TSP01_SP0R-RQID_CHAR.
SPOOLID = G_SPOOL_NUM.
CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
EXPORTING
SPOOLID = SPOOLID
IMPORTING
RC =
STATUS =
ERROR_MESSAGE =
.
10-02-2008 11:37 AM
Hi nihad,
After displaying your report in the menu bar goto list and click on print will give you a spool request number at the status bar.
Take the spool number and goto program RSTXPDFT4 and execute will ask you to enter the spool request number there u enter and will give you PDF format of your report. Use that report in your program may solve your issue.
Cheers!!
10-02-2008 11:38 AM
I can't catch the error, could you run this report in debug mode to see where this logic falls?
Thanks
10-02-2008 2:47 PM
I want this porgram to create pdf file from my spool and save it to hard disk.
Is it possible to do this? please guys have a look at code in my first post..
Additionally may I use some function modules to send this output pdf to an email???
Nihad