05-22-2007 4:00 PM
Hi,
Can anyonce briefly explain me how the output of a smartform can be attached as a PDF file to a mail.
Ques 1: Do we need to pass any explicit value to the smart form generated function module. If so, what is the value and to which parameter do we need to pass.
Ques 2: As far as i know OTF is converted to PDF. If this is so please explain how this is done.
Ques 3: How can a PDF document be made as an attachment, to a mail.
If anyone can provide me an example it would be very great.
Thanks & Regards,
Goutham.
05-22-2007 4:05 PM
05-22-2007 4:05 PM
05-22-2007 4:06 PM
Hi,
Go through the following code:
REPORT z_smtf_pdf_and_email_aks01.
DATA: x_ctrl_p TYPE ssfctrlop,
x_output_data TYPE ssfcrescl.
DATA: it_docs LIKE docs OCCURS 0 WITH HEADER LINE,
it_lines LIKE tline OCCURS 0 WITH HEADER LINE,
it_packing LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE.
*-----Initialisation
x_ctrl_p-no_dialog = 'X'.
x_ctrl_p-getotf = 'X'.
x_ctrl_p-langu = sy-langu.
----
Internal Tables Declaration *
----
DATA: it_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,
it_pcklist LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
it_mess LIKE solisti1 OCCURS 0 WITH HEADER LINE,
it_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,
it_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
it_table LIKE solix OCCURS 0 WITH HEADER LINE.
DATA: it_soli LIKE soli OCCURS 0 WITH HEADER LINE.
*-----Work area declaration
DATA: wa_doc_data TYPE sodocchgi1.
----
Variable Declaration *
----
DATA: v_lines_txt TYPE i,
v_lines_bin TYPE i,
v_lines TYPE i,
v_fname TYPE rs38l_fnam,
v_size TYPE i,
v_filename TYPE rlgrap-filename.
----
Start of selection event *
----
START-OF-SELECTION.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'Z_SMTF_TEST_AKS01'
IMPORTING
fm_name = v_fname.
CALL FUNCTION v_fname
EXPORTING
control_parameters = x_ctrl_p
IMPORTING
job_output_info = x_output_data.
*-----Calling fumction module to convert output to pdf.
CALL FUNCTION 'CONVERT_OTF_2_PDF'
IMPORTING
bin_filesize = v_size
TABLES
otf = x_output_data-otfdata
doctab_archive = it_docs
lines = it_lines.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 134
IMPORTING
bin_filesize = v_size
TABLES
otf = x_output_data-otfdata
lines = it_lines
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
OTHERS = 4.
CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
EXPORTING
line_width_dst = 255
TABLES
content_in = it_lines
content_out = it_soli
EXCEPTIONS
err_line_width_src_too_long = 1
err_line_width_dst_too_long = 2
err_conv_failed = 3
OTHERS = 4.
CALL FUNCTION 'ZFUNC_CONVERT_DATA_ODC01'
EXPORTING
iv_byte_mode = 'X'
TABLES
it_data = it_lines
et_data = it_table.
*-----To caluculate total number of lines of internal table
DESCRIBE TABLE it_table LINES v_lines.
*-----Function module to download the output file.
CALL FUNCTION 'DOWNLOAD'
EXPORTING
bin_filesize = v_size
filename = ' '
filetype = 'BIN'
IMPORTING
act_filename = v_filename
TABLES
data_tab = it_lines.
*-----Create Message Body and Title and Description
it_mess =
'i have successfully converted smartform from otf format to pdf' .
" and i have attached that in mail'.
APPEND it_mess.
wa_doc_data-obj_name = 'smartform'.
wa_doc_data-expiry_dat = sy-datum + 10.
wa_doc_data-obj_descr = 'smartform'.
wa_doc_data-sensitivty = 'F'.
wa_doc_data-doc_size = v_lines * 255.
APPEND it_pcklist.
*-----PDF Attachment
it_pcklist-transf_bin = 'X'.
it_pcklist-head_start = 1.
it_pcklist-head_num = 0.
it_pcklist-body_start = 1.
it_pcklist-doc_size = v_lines_bin * 255 .
it_pcklist-body_num = v_lines.
it_pcklist-doc_type = 'PDF'.
it_pcklist-obj_name = 'smartform'.
it_pcklist-obj_descr = 'smart_desc'.
it_pcklist-obj_langu = 'E'.
it_pcklist-doc_size = v_lines * 255.
APPEND it_pcklist.
*-----Giving the receiver email-id
CLEAR it_receivers.
it_receivers-receiver = 'wereqpk@yahoo.com'
it_receivers-rec_type = 'U'.
APPEND it_receivers.
CLEAR it_receivers.
it_receivers-receiver = 'peqek@yahoo.com'.
it_receivers-rec_type = 'U'.
APPEND it_receivers.
CLEAR it_receivers.
it_receivers-receiver = 'pk@yahoo.com'.
it_receivers-rec_type = 'U'.
APPEND it_receivers.
*-----Calling the function module to sending email
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = wa_doc_data
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = it_pcklist
contents_txt = it_mess
contents_hex = it_table
receivers = it_receivers
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
IF sy-subrc = 0.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
WITH rfcgroup = 'iwdf7ytc_YD3_94'
AND RETURN.
REFRESH: it_receivers,
it_mess,
it_pcklist.
ENDIF.
Reward points if helpful answer.
Ashvender
06-19-2007 2:07 PM
Sorry,
but i didn't know a function called 'ZFUNC_CONVERT_DATA_ODC01'.
What's the use of it?
Manuela
06-19-2007 2:24 PM
Hi Manuela,
Actually that FM need not be used. I think that has been used for some specific purpose in the program. The requirement was to send it as E-Mail, but the download code is given there.
Anyways for download even without using that FM it works.
Please let me know if further details are required.
Regards,
Goutham.
P.S.: I have posted this question.
10-27-2007 8:05 AM
Hi Ashvender Kumar,
I had seen the program which you posted in SDN for sending the smartform to mail through PDF format.
It is very good and helped me lot.I copied and tried.
But in this program you used one <b>user defined function module</b>. No details about that one. Anyway i commented that function module and executed the program.
Everything is fine, mail was sent in pdf format.
But it is not getting open, because it is not supported by file type or file may be damaged.
Can you send me the details of that function module
<b>'ZFUNC_CONVERT_DATA_ODC01'</b>. so that my work will be completed.