DATA: ldf_mailsubject TYPE sodocchgi1.
DATA: ldt_packing_list TYPE STANDARD TABLE OF sopcklsti1,
lds_packing_list TYPE sopcklsti1.
DATA: ldt_recipients TYPE STANDARD TABLE OF somlreci1,
lts_recipients TYPE somlreci1.
* populate email subject (document_data) structure
ldf_mailsubject-obj_name = gcf_mailsubject.
ldf_mailsubject-obj_langu = sy-langu.
ldf_mailsubject-obj_descr = prt_email_subject.
ldf_mailsubject-sensitivty = gcf_f.
ldf_mailsubject-doc_size = ( ldf_attach_cnt - 1 ) * 255 +
STRLEN( gdt_attachment ).
* email body
lds_packing_list-transf_bin = space.
lds_packing_list-head_start = 1.
lds_packing_list-head_num = 0.
lds_packing_list-body_start = 1.
lds_packing_list-body_num = ldf_body_cnt.
lds_packing_list-doc_type = gcf_raw.
APPEND lds_packing_list TO ldt_packing_list.
CLEAR lds_packing_list.
* email attachment
lds_packing_list-transf_bin = gcf_x.
lds_packing_list-head_start = 1.
lds_packing_list-head_num = 1.
lds_packing_list-body_start = 1.
lds_packing_list-body_num = ldf_attach_cnt.
lds_packing_list-doc_type = gcf_xls. "text file
lds_packing_list-obj_name = gcf_mailattach.
lds_packing_list-obj_descr = prt_attach_descr.
lds_packing_list-doc_size = lds_packing_list-body_num * 255.
APPEND lds_packing_list TO ldt_packing_list.
CLEAR lds_packing_list.
* Call SAP Office function to send the email out
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = ldf_mailsubject
put_in_outbox = ' '
TABLES
packing_list = ldt_packing_list
contents_bin = gdt_attachment
receivers = ldt_recipients
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.
CASE sy-subrc.
WHEN 0.
COMMIT WORK.
* Push mail out from SAP outbox
SUBMIT rsconn01 WITH mode = 'INT' AND RETURN.
MESSAGE s000(zev0301) WITH text-m03. "Email successfully sent
DATA: ldt_packing_list TYPE STANDARD TABLE OF sopcklsti1,
lds_packing_list TYPE sopcklsti1.
DATA: ldt_recipients TYPE STANDARD TABLE OF somlreci1,
lts_recipients TYPE somlreci1.
* populate email subject (document_data) structure
ldf_mailsubject-obj_name = gcf_mailsubject.
ldf_mailsubject-obj_langu = sy-langu.
ldf_mailsubject-obj_descr = prt_email_subject.
ldf_mailsubject-sensitivty = gcf_f.
ldf_mailsubject-doc_size = ( ldf_attach_cnt - 1 ) * 255 +
STRLEN( gdt_attachment ).
* email body
lds_packing_list-transf_bin = space.
lds_packing_list-head_start = 1.
lds_packing_list-head_num = 0.
lds_packing_list-body_start = 1.
lds_packing_list-body_num = ldf_body_cnt.
lds_packing_list-doc_type = gcf_raw.
APPEND lds_packing_list TO ldt_packing_list.
CLEAR lds_packing_list.
* email attachment
lds_packing_list-transf_bin = gcf_x.
lds_packing_list-head_start = 1.
lds_packing_list-head_num = 1.
lds_packing_list-body_start = 1.
lds_packing_list-body_num = ldf_attach_cnt.
lds_packing_list-doc_type = gcf_xls. "text file
lds_packing_list-obj_name = gcf_mailattach.
lds_packing_list-obj_descr = prt_attach_descr.
lds_packing_list-doc_size = lds_packing_list-body_num * 255.
APPEND lds_packing_list TO ldt_packing_list.
CLEAR lds_packing_list.
* Call SAP Office function to send the email out
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = ldf_mailsubject
put_in_outbox = ' '
TABLES
packing_list = ldt_packing_list
contents_bin = gdt_attachment
receivers = ldt_recipients
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.
CASE sy-subrc.
WHEN 0.
COMMIT WORK.
* Push mail out from SAP outbox
SUBMIT rsconn01 WITH mode = 'INT' AND RETURN.
MESSAGE s000(zev0301) WITH text-m03. "Email successfully sent
No comments:
Post a Comment