on 01-11-2010 7:54 AM
Hi All,
I have to send mail with PDF file.
PDF file shoud contain smartform output .
i am gettign imported from smarform output into table of job_output and i am passing the imported value to FM CONVERT_OTF
job_output-otfdata[].
but i am gettng dump from CONVERT_OTF.
due to BAD data, i am getting this error for numeric conversion from this FM CONVERT_OTF..
what we can do to avoid this kind of issues.
please suggest me on this.
How did you declare BIN_FILESIZE.
Is it declared of type i.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Before calling your SF FM, make
control_parameters-GETOTF = 'X'.
it means your SF output is converted to OTF format. Spool will not be create
so in order to concert OTF to PDF use,
DATA:bin_filesize TYPE i.
DATA:it_pdfdata TYPE TABLE OF tline WITH HEADER LINE.
DATA:it_pdf TYPE table of solisti1,
it_pdf_255 TYPE table of solisti1.
it_pdfdata[] = t_job_output_info-otfdata[].
CALL FUNCTION *'CONVERT_OTF'*
EXPORTING
FORMAT = 'PDF'
IMPORTING
BIN_FILESIZE = bin_filesize
TABLES
otf = it_pdfdata
lines = it_pdf
EXCEPTIONS
ERR_MAX_LINEWIDTH = 1
ERR_FORMAT = 2
ERR_CONV_NOT_POSSIBLE = 3
ERR_BAD_OTF = 4
OTHERS = 5 .
then to send it as Email attachemnt we need to format the PDF data
i.e.
CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
EXPORTING
LINE_WIDTH_SRC = '134'
LINE_WIDTH_DST = '255'
TABLES
content_in = it_pdf
content_out = it_pdf_255
EXCEPTIONS
ERR_LINE_WIDTH_SRC_TOO_LONG = 1
ERR_LINE_WIDTH_DST_TOO_LONG = 2
ERR_CONV_FAILED = 3
OTHERS = 4 .
then put your mail details
for example
*"Types
TYPES: t_document_data TYPE sodocchgi1,
t_packing_list TYPE sopcklsti1,
t_attachment TYPE solisti1,
t_body_msg TYPE solisti1,
t_receivers TYPE somlreci1,
t_pdf TYPE tline.
*"Workareas
DATA : w_document_data TYPE t_document_data,
w_packing_list TYPE t_packing_list,
w_attachment TYPE t_attachment,
w_body_msg TYPE t_body_msg,
w_receivers TYPE t_receivers,
w_pdf TYPE t_pdf.
*Internal Tables
DATA : i_document_data TYPE STANDARD TABLE OF t_document_data,
i_packing_list TYPE STANDARD TABLE OF t_packing_list,
i_attachment TYPE STANDARD TABLE OF t_attachment,
i_body_msg TYPE STANDARD TABLE OF t_body_msg,
i_receivers TYPE STANDARD TABLE OF t_receivers,
i_pdf TYPE STANDARD TABLE OF t_pdf.
*Subject of the mail.
w_document_data-obj_name = 'MAIL_TO_HEAD'.
w_document_data-obj_descr = 'File name'.
*Fill the document data and get size of attachment
w_document_data-obj_langu = sy-langu.
"Body of the mail
w_body_msg = 'Hello,'.
APPEND w_body_msg TO i_body_msg.
CLEAR w_body_msg.
w_body_msg = ' '.
APPEND w_body_msg TO i_body_msg.
CLEAR w_body_msg.
w_body_msg = 'Please find the attached file'.
APPEND w_body_msg TO i_body_msg.
CLEAR w_body_msg.
w_body_msg = ' '.
APPEND w_body_msg TO i_body_msg.
CLEAR w_body_msg.
w_body_msg = 'Regards,'.
APPEND w_body_msg TO i_body_msg.
CLEAR w_body_msg.
w_body_msg = sy-uname.
APPEND w_body_msg TO i_body_msg.
CLEAR w_body_msg.
*"Write Packing List for Body
clear w_pdf.
DESCRIBE TABLE i_body_msg LINES g_tab_lines.
read table it_pdf_255 into w_pdf index g_tab_lines.
w_document_data-doc_size = ( g_tab_lines - 1 ) * 255 +
STRLEN( w_attachment ).
w_packing_list-head_start = 1.
w_packing_list-head_num = 0.
w_packing_list-body_start = 1.
w_packing_list-body_num = g_tab_lines.
w_packing_list-doc_type = 'RAW'.
APPEND w_packing_list TO i_packing_list.
CLEAR w_packing_list.
*"Write Packing List for Attachment
w_packing_list-transf_bin = 'X'.
w_packing_list-head_start = 1.
w_packing_list-head_num = 1.
w_packing_list-body_start = 1.
DESCRIBE TABLE it_pdf_255 LINES w_packing_list-body_num.
w_packing_list-doc_type = 'PDF'.
w_packing_list-obj_descr = 'PDF Attachment'.
w_packing_list-obj_name = 'PDF_ATTACHMENT'.
w_packing_list-doc_size = w_packing_list-body_num * 255.
APPEND w_packing_list TO i_packing_list.
CLEAR w_packing_list.
* Receivers List.
* completing the recipient list for email
CLEAR w_receivers.
refresh:i_receivers.
w_receivers-receiver = nast-TDCOVTITLE.
w_receivers-rec_type = 'U'.
w_receivers-notif_read = 'X'.
APPEND w_receivers TO i_receivers .
CLEAR:w_receivers.
* send the document
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = w_document_data
put_in_outbox = 'X'
COMMIT_WORK = 'X'
TABLES
packing_list = i_packing_list
contents_bin = it_pdf_255
contents_txt = i_body_msg
receivers = i_receivers
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
OTHERS = 99.
IF sy-subrc <> 0.
message 'Error When Sending the File' type 'I'.
else.
message 'Email sent' type 'I'.
ENDIF.
Please try the above code. Its working
Otherwise you can refer
[http://an-abaper.blogspot.com/2009/07/sending-smartform-as-pdf-through-mail.html]
Thanks
Sangeetha
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi radha ,
I think the parameters that you are passing to that function module may be wrong, so try using the function module "CONVERT_OTF_2_PDF" . i have given a sample code for converting the smartform to pdf format , you could use that for converting that into pdf and then to send it as mail to the receiver you could use BCS mail classes .
TABLES : VBAP.
Internal table declaration
DATA: it_otf TYPE STANDARD TABLE OF itcoo,
it_docs TYPE STANDARD TABLE OF docs,
it_lines TYPE STANDARD TABLE OF tline.
Declaration of local variables.
DATA:
st_job_output_info TYPE ssfcrescl,
st_document_output_info TYPE ssfcrespd,
st_job_output_options TYPE ssfcresop,
st_output_options TYPE ssfcompop,
st_control_parameters TYPE ssfctrlop,
v_len_in TYPE so_obj_len,
v_language TYPE sflangu VALUE 'E',
v_e_devtype TYPE rspoptype,
v_bin_filesize TYPE i,
v_name TYPE string,
v_path TYPE string,
v_fullpath TYPE string,
v_filter TYPE string,
v_uact TYPE i,
v_guiobj TYPE REF TO cl_gui_frontend_services,
v_filename TYPE string,
v_fm_name TYPE rs38l_fnam.
CONSTANTS c_formname TYPE tdsfname VALUE 'Z417_PE2_MM_PO'.
PARAMETER: p_vbeln type vbak-vbeln. " Sales Order No
data : BEGIN OF it_saleshead occurs 0,
vbeln type vbak-vbeln, " sales order number
erdat type vbak-erdat, " created date
kunnr type vbak-kunnr, " Customer NUmber
name1 type kna1-name1, " customer Name
telf1 type kna1-telf1, " Telephone number
telfx type kna1-telfx, " Fax number
end of it_saleshead.
internal table declaration for Item data
DATA : IT_SALESITEM LIKE STANDARD TABLE OF VBAP WITH HEADER LINE.
CALL FUNCTION 'SSF_GET_DEVICE_TYPE'
EXPORTING
i_language = v_language
i_application = 'SAPDEFAULT'
IMPORTING
e_devtype = v_e_devtype.
st_output_options-tdprinter = v_e_devtype.
st_control_parameters-no_dialog = 'X'.
st_control_parameters-getotf = 'X'.
START-OF-SELECTION.
Data Retrieval
PERFORM data_retrieve .
.................GET SMARTFORM FUNCTION MODULE NAME.................
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = c_formname
IMPORTING
fm_name = v_fm_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
...........................CALL SMARTFORM............................
CALL FUNCTION v_fm_name
EXPORTING
control_parameters = st_control_parameters
output_options = st_output_options
user_settings = space
IMPORTING
document_output_info = st_document_output_info
job_output_info = st_job_output_info
job_output_options = st_job_output_options
TABLES
IT_HEAD = IT_SALESHEAD
IT_ITEM = it_salesitem
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
.........................CONVERT TO OTF TO PDF.......................
CALL FUNCTION 'CONVERT_OTF_2_PDF'
IMPORTING
bin_filesize = v_bin_filesize
TABLES
otf = st_job_output_info-otfdata
doctab_archive = it_docs
lines = it_lines
EXCEPTIONS
err_conv_not_possible = 1
err_otf_mc_noendmarker = 2
OTHERS = 3.
........................GET THE FILE NAME TO STORE....................
CONCATENATE 'smrt' '.pdf' INTO v_name.
CREATE OBJECT v_guiobj.
CALL METHOD v_guiobj->file_save_dialog
EXPORTING
default_extension = 'pdf'
default_file_name = v_name
file_filter = v_filter
CHANGING
filename = v_name
path = v_path
fullpath = v_fullpath
user_action = v_uact.
IF v_uact = v_guiobj->action_cancel.
EXIT.
ENDIF.
..................................DOWNLOAD AS FILE....................
MOVE v_fullpath TO v_filename.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
bin_filesize = v_bin_filesize
filename = v_filename
filetype = 'BIN'
TABLES
data_tab = it_lines
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
OTHERS = 22.
&----
*& Form DATA_RETRIEVE
&----
text
----
<--P_CUSTOMER[] text
<--P_BOOKINGS[] text
<--P_CONNECTIONS[] text
----
FORM DATA_RETRIEVE .
if p_vbeln is not INITIAL.
select a~vbeln " sales order number
a~erdat " Created date
a~kunnr " customer Number
b~name1 " Name of the Customer
b~telf1 " Telephone NUmber
b~telfx " Fax Number
from vbak as a inner join
kna1 as b on akunnr = bkunnr
into table it_saleshead
where vbeln eq p_vbeln .
endif.
if it_saleshead[] is not INITIAL.
select vbeln " sales order number
posnr " item number
matnr " material NUmber
kwmeng " Quantity
netwr " Unit Price
netpr " Net Price of the Material
from vbap
INTO CORRESPONDING FIELDS OF TABLE it_salesitem
FOR ALL ENTRIES IN it_saleshead
where vbeln eq it_saleshead-vbeln.
if sy-subrc eq 0.
message i051(z417_msg).
else.
message i001(z417_msg).
endif.
else.
message i001(z417_msg).
endif.
ENDFORM. " DATA_RETRIEVE
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this code snippet
VARIABLES ***
data: fm_name type rs38l_fnam.
data: st_control_parameters type ssfctrlop.
data: v_fm_name type rs38l_fnam.
data: st_job_output_info type ssfcrescl,
st_document_output_info type ssfcrespd,
st_job_output_options type ssfcresop,
v_bin_filesize type i,
v_name type string,
v_path type string,
v_fullpath type string.
data: it_otf type standard table of itcoo,
it_docs type standard table of docs,
it_lines type standard table of tline,
v_guiobj type ref to cl_gui_frontend_services,
v_filename type string,
v_filter type string,
VARIABLES END HERE ***
st_control_parameters-getotf = 'X'. " for PDF
call function 'SSF_FUNCTION_MODULE_NAME'
exporting
formname = 'FORMNAME'
importing
fm_name = v_fm_name
exceptions
no_form = 1
no_function_module = 2
others = 3.
call function v_fm_name
exporting
control_parameters = st_control_parameters
output_options = st_output_options
PARAMETER1 = PARAMETER1
importing
document_output_info = st_document_output_info
job_output_info = st_job_output_info
job_output_options = st_job_output_options
tables
itab = itab
exceptions
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
others = 5.
if sy-subrc eq 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
else.
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
text = 'Writing output into PDF'.
CONVERT TO OTF TO PDF.......................
call function 'CONVERT_OTF_2_PDF'
importing
bin_filesize = v_bin_filesize
tables
otf = st_job_output_info-otfdata
doctab_archive = it_docs
lines = it_lines
exceptions
err_conv_not_possible = 1
err_otf_mc_noendmarker = 2
others = 3.
if sy-subrc eq 0.
*
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
GET THE FILE NAME TO STORE....................
concatenate 'FILENAME' '.pdf' into v_name.
create object v_guiobj.
call method v_guiobj->file_save_dialog
exporting
default_extension = 'pdf'
default_file_name = v_name
file_filter = v_filter
changing
filename = v_name
path = v_path
fullpath = v_fullpath
user_action = v_uact.
if v_uact = v_guiobj->action_cancel.
exit.
endif.
DOWNLOAD AS FILE....................
move v_fullpath to v_filename.
call function 'GUI_DOWNLOAD'
exporting
bin_filesize = v_bin_filesize
filename = v_filename
filetype = 'BIN'
tables
data_tab = it_lines
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
others = 22.
if sy-subrc eq 0.
*
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endif.
Get back to me if there are any problems.
Regards,
Shehryar Shabbir
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
same code has been implemented.
dump is comign due to calculation of sizefield is BIN_FILESIZE from the FM CONVERT_OTF.
from the followign code when 'PDF'.
Subroutine is :
PERFORM CONVERT_OTF_2_PDF(RSTXCPDF) TABLES OTF LINES
USING BIN_FILESIZE
ARCHIVE_INDEX.
this subroutine returns BIN_FILESIZE as '*982'
and comparign with zero.
IF BIN_FILESIZE < 0.
hence we are gettggn dump.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.