12-09-2009 7:49 PM
Hello!
I have a problem.
I'll try to explain it toy you.
I have a SapScript that the user has the option to send it to the printer or have a Print Preview. I need to send it by mail in PDF format.
If the user select PRINT, a spool id is created, I can get the OTF, generate the PDF and send it by mail. Everything OK with that.
The problem is if the user select PRINT PREVIEW I don't get a spool id. So, what I did is to get the OTF from the CLOSE_FORM MF and generate de PDF from there. I tried several FM to generate the PDF but for sure I'm doing something wrong, because or the PDF is corrupted or I have a problem with the parameters in the SO_NEW_DOCUMENT_ATT_SEND_API1 FM.
So, what I need it: Generate a PDF from a OTF imported from CLOSE_FORM FM and send it by mail.
Examples or the FM I can use are welcome.
I tried to do search here, but I couldn't find anything that may help me..
So, please... Show me the light!!!
Thanks!!!
Bettina
12-09-2009 7:58 PM
Here is an example.
data: maildata like sodocchgi1.
data: mailpack like sopcklsti1 occurs 2 with header line.
data: mailhead like solisti1 occurs 1 with header line.
data: mailbin like solisti1 occurs 10 with header line.
data: mailtxt like solisti1 occurs 10 with header line.
data: mailrec like somlrec90 occurs 0 with header line.
data: solisti1 like solisti1 occurs 0 with header line.
data: lv_email_address type string.
data: tab_lines like sy-tabix.
data: begin of otf occurs 0.
include structure itcoo .
data: end of otf.
Regards,
Rich Heilman
Edited by: Rich Heilman on Dec 9, 2009 2:58 PM
Splitting source code.... geezzz
12-09-2009 7:59 PM
12-09-2009 7:59 PM
Part 3
* Send Report
clear: maildata, mailtxt, mailbin, mailpack, mailhead, mailrec.
refresh: mailtxt, mailbin, mailpack, mailhead, mailrec.
* Creation of the document to be sent File Name
maildata-obj_name = 'REPORT'.
* Mail Subject
maildata-obj_descr = 'Your Report'.
describe table mailtxt lines tab_lines.
read table mailtxt index tab_lines.
maildata-doc_size = ( tab_lines - 1 ) * 255 + strlen( mailtxt ).
* Creation of the entry for the compressed document
clear mailpack-transf_bin.
mailpack-head_start = 1.
mailpack-head_num = 0.
mailpack-body_start = 1.
mailpack-body_num = tab_lines.
mailpack-doc_type = 'RAW'.
append mailpack.
* Creation of the document attachment
loop at solisti1.
move-corresponding solisti1 to mailbin.
append mailbin.
endloop.
describe table mailbin lines tab_lines.
mailhead = 'REPORT.OTF'.
append mailhead.
** Creation of the entry for the compressed attachment
mailpack-transf_bin = 'X'.
mailpack-head_start = 1.
mailpack-head_num = 1.
mailpack-body_start = 1.
mailpack-body_num = tab_lines.
mailpack-doc_type = 'OTF'.
mailpack-obj_name = 'ATTACHMENT'.
mailpack-obj_descr = 'Some Report'.
mailpack-doc_size = tab_lines * 255.
append mailpack.
mailrec-receiver = lv_email_address. "<-- a valid email address
mailrec-rec_type = 'U'.
append mailrec.
* Sending the document
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = maildata
put_in_outbox = 'X'
tables
packing_list = mailpack
object_header = mailhead
contents_bin = mailbin
contents_txt = mailtxt
receivers = mailrec
exceptions
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
others = 99.
Regards,
Rich Heilman
12-09-2009 8:03 PM
12-09-2009 8:09 PM
12-09-2009 8:14 PM
12-09-2009 8:41 PM
Rich, I copy pasted your code and I replaced:
mailpack-doc_type = 'OTF'.
for
mailpack-doc_type = 'PDF'
and
mailhead = 'REPORT.OTF'.
for
mailhead = 'REPORT.PDF'.
But no luck yet...
When I open the attachment I get a message error:
"Adobe Reader could not open "nameofthefile.pdf" because it is either not a upported file or because the file has been damaged (for example it was sent as an email attachment and wasn't correctly decoded)."
With your original code, I receive a sap document that shows text.
12-09-2009 10:23 PM
12-09-2009 10:26 PM
12-11-2009 12:39 AM
I solved this doing a 2nd run, generating a spool order, then to pdf and after that, deleteing that spool order.
Thanks for your time Rich!