Code: Alles auswählen.
* Internal Table declarations
data: i_otf type itcoo occurs 0 with header line,
i_tline type table of tline with header line,
i_receivers type table of somlreci1 with header line,
i_record like solisti1 occurs 0 with header line,
* Objects to send mail.
i_objpack like sopcklsti1 occurs 0 with header line,
i_objtxt like solisti1 occurs 0 with header line,
i_objbin like solisti1 occurs 0 with header line,
i_reclist like somlreci1 occurs 0 with header line,
* Work Area declarations
w_objhead type soli_tab,
w_ctrlop type ssfctrlop,
w_compop type ssfcompop,
w_return type ssfcrescl,
w_doc_chng type sodocchgi1,
w_data type sodocchgi1,
w_buffer type string,"To convert from 132 to 255
* Variables declarations
v_form_name type rs38l_fnam,
v_len_in like sood-objlen,
v_len_out like sood-objlen,
v_len_outn type i,
v_lines_txt type i,
v_lines_bin type i.
data: carr_id type sbook-carrid,
fm_name type rs38l_fnam.
data: customer type scustom,
bookings type ty_bookings,
connections type ty_connections.
parameter: p_custid type scustom-id default 21.
select-options: s_carrid for carr_id default 'LH' to 'LH'.
parameter: p_form type tdsfname default 'SF_EXAMPLE_01',
p_email type somlreci1-receiver default 'deine_email.com'.
* get data
select single * from scustom into customer where id = p_custid.
check sy-subrc = 0.
select * from sbook into table bookings
where customid = p_custid
and carrid in s_carrid
order by primary key.
select * from spfli into table connections
for all entries in bookings
where carrid = bookings-carrid
and connid = bookings-connid
order by primary key.
* print data
call function 'SSF_FUNCTION_MODULE_NAME'
exporting formname = p_form
* variant = ' '
* direct_call = ' '
importing fm_name = fm_name
exceptions no_form = 1
no_function_module = 2
others = 3.
if sy-subrc <> 0.
* error handling
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
exit.
endif.
w_ctrlop-getotf = 'X'.
w_ctrlop-no_dialog = 'X'.
w_compop-tdnoprev = 'X'.
call function fm_name
exporting
control_parameters = w_ctrlop
output_options = w_compop
user_settings = 'X'
customer = customer
bookings = bookings
connections = connections
importing
job_output_info = w_return
exceptions
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
others = 5.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
i_otf[] = w_return-otfdata[].
call function 'CONVERT_OTF'
exporting
format = 'PDF'
max_linewidth = 132
importing
bin_filesize = v_len_in
tables
otf = i_otf
lines = i_tline
exceptions
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
others = 4.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
* Convert PDF from 132 to 255.
loop at i_tline.
* Replacing space by ~
translate i_tline using ' ~'.
concatenate w_buffer i_tline into w_buffer.
endloop.
* Replacing ~ by space
translate w_buffer using '~ '.
do.
i_record = w_buffer.
* Appending 255 characters as a record
append i_record.
shift w_buffer left by 255 places.
if w_buffer is initial.
exit.
endif.
enddo.
refresh: i_reclist,
i_objtxt,
i_objbin,
i_objpack.
clear w_objhead.
* Object with PDF.
i_objbin[] = i_record[].
describe table i_objbin lines v_lines_bin.
* Object with main text of the mail.
i_objtxt = 'Find attached the output of the smart form.'.
append i_objtxt.
i_objtxt = 'Regards,'.
append i_objtxt.
i_objtxt = sy-uname.
append i_objtxt.
describe table i_objtxt lines v_lines_txt.
* Document information.
w_doc_chng-obj_name = 'Smartform'.
w_doc_chng-expiry_dat = sy-datum + 10.
w_doc_chng-obj_descr = 'Smart form output'.
w_doc_chng-sensitivty = 'F'. "Functional object
w_doc_chng-doc_size = v_lines_txt * 255.
* Pack to main body as RAW.
* Obj. to be transported not in binary form
clear i_objpack-transf_bin.
* Start line of object header in transport packet
i_objpack-head_start = 1.
* Number of lines of an object header in object packet
i_objpack-head_num = 0.
* Start line of object contents in an object packet
i_objpack-body_start = 1.
* Number of lines of the object contents in an object packet
i_objpack-body_num = v_lines_txt.
* Code for document class
i_objpack-doc_type = 'RAW'.
append i_objpack.
* Packing as PDF.
i_objpack-transf_bin = 'X'.
i_objpack-head_start = 1.
i_objpack-head_num = 1.
i_objpack-body_start = 1.
i_objpack-body_num = v_lines_bin.
i_objpack-doc_type = 'PDF'.
i_objpack-obj_name = 'Smartform'.
concatenate 'Smartform_output' '.pdf'
into i_objpack-obj_descr.
i_objpack-doc_size = v_lines_bin * 255.
append i_objpack.
* Document information.
clear i_reclist.
* e-mail receivers.
i_reclist-receiver = p_email.
i_reclist-express = 'X'.
i_reclist-rec_type = 'U'. "Internet address
append i_reclist.
* Sending mail.
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = w_doc_chng
put_in_outbox = 'X'
tables
packing_list = i_objpack
object_header = w_objhead
contents_hex = i_objbin
contents_txt = i_objtxt
receivers = i_reclist
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.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
Code: Alles auswählen.
data: data: l_txt(255) type c,
gt_text type bcsy_text.
field-symbols: <otf> type itcoo.
*--- OTF Daten in einfache Textstruktur schreiben
loop at w_return-otfdata assigning <otf>.
concatenate <otf>-tdprintcom <otf>-tdprintpar into l_txt.
append l_txt to gt_text.
endloop.