Code: Alles auswählen.
METHOD send_email_att.
DATA: ls_document_data TYPE sodocchgi1,
ls_receiver TYPE somlreci1,
lt_object_content TYPE TABLE OF solisti1,
lt_receiver TYPE TABLE OF somlreci1,
lv_line_content TYPE so_text255,
ls_message TYPE …ts_message,
lv_number TYPE char10,
lt_objpack TYPE TABLE OF sopcklsti1,
tab_lines LIKE sy-tabix,
ls_objpack TYPE sopcklsti1,
lt_objhead TYPE TABLE OF solisti1,
ls_objhead TYPE solisti1,
lv_string TYPE solisti1,
ls_objbin TYPE solisti1,
lt_objbin TYPE TABLE OF solisti1 INITIAL SIZE 1.
CONSTANTS: lc_obj_langu VALUE 'D',
lc_sensitivty VALUE 'O',
lc_rec_type VALUE 'U',
lc_com_type(3) VALUE 'INT'.
po_ok = abap_true.
IF pi_receiver IS INITIAL OR pi_messages IS INITIAL.
RETURN.
ENDIF.
ls_receiver-receiver = pi_receiver.
lv_line_content = pi_email_head.
CLEAR lv_line_content.
APPEND lv_line_content TO lt_object_content.
LOOP AT pi_messages INTO ls_message.
lv_line_content = ls_message-message.
APPEND lv_line_content TO lt_object_content.
* add empty line
CLEAR: lv_line_content, lv_number.
APPEND lv_line_content TO lt_object_content.
ENDLOOP.
ls_document_data-obj_name = pi_obj_name. " 'Test mail'
ls_document_data-obj_descr = pi_email_head. " 'E-Mail mit Anhang'
ls_document_data-obj_langu = lc_obj_langu. "VALUE 'D'.
ls_document_data-sensitivty = lc_sensitivty. "VALUE 'O'.
APPEND ls_document_data-obj_name to lt_object_content.
* set receiver of the message
CLEAR lt_receiver.
ls_receiver-rec_type = lc_rec_type. "VALUE 'U'.
ls_receiver-com_type = lc_com_type. "VALUE 'INT'.
APPEND ls_receiver TO lt_receiver.
* Erstellen des Eintrags zum komprimierten Dokument
READ TABLE lt_objpack INDEX 1 INTO ls_objpack .
CLEAR ls_objpack-transf_bin.
ls_objpack-head_start = 1.
ls_objpack-head_num = 0.
ls_objpack-body_start = 1.
ls_objpack-body_num = tab_lines.
ls_objpack-doc_type = 'RAW'.
APPEND ls_objpack TO lt_objpack.
* Erstellen der Anlage für das Dokument.
LOOP AT pi_t_report INTO ls_objbin.
lv_string = ls_objbin-line .
APPEND lv_string TO lt_objbin .
ENDLOOP.
DESCRIBE TABLE lt_objbin LINES tab_lines.
* Anhang - Name
READ TABLE lt_objhead INDEX 1 INTO ls_objhead .
ls_objhead = 'Report.TXT'.
APPEND ls_objhead TO lt_objhead .
* Erstellen des Eintrags zur komprimierten Anlage
ls_objpack-transf_bin = 'X'.
ls_objpack-head_start = 1.
ls_objpack-head_num = 1.
ls_objpack-body_start = 1.
ls_objpack-body_num = tab_lines.
ls_objpack-doc_type = 'TXT'.
ls_objpack-obj_name = 'ANLAGE'.
ls_objpack-obj_descr = 'Report'.
ls_objpack-doc_size = tab_lines * 255.
APPEND ls_objpack TO lt_objpack.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = ls_document_data
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = lt_objpack
object_header = lt_objhead
contents_bin = lt_objbin
contents_txt = lt_object_content
receivers = lt_receiver
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.
CLEAR po_ok.
ENDIF.
COMMIT WORK.
ENDMETHOD.
Code: Alles auswählen.
ls_objpack-body_num = tab_lines.
ls_objpack-doc_type = 'TXT'. "====> 'RAW'
ls_objpack-obj_name = 'ANLAGE'.
ls_objpack-obj_descr = 'Report'.
Code: Alles auswählen.
report.
parameters: pi_recv type so_recname default 'user@abapforum.de'.
parameters: pi_head type so_text255 default 'email header'.
parameters: pi_objn type so_obj_nam default 'my email'.
data: ls_document_data type sodocchgi1,
ls_receiver type somlreci1,
lt_solisti1 type table of solisti1,
lt_object_content type table of solisti1,
lt_receiver type table of somlreci1,
lv_line_content type so_text255,
lt_messages type table of bapireturn-message,
ls_message type bapireturn-message,
lt_objpack type table of sopcklsti1,
ls_objpack type sopcklsti1,
lt_objhead type table of solisti1,
ls_objhead type solisti1.
constants: lc_obj_langu value 'D',
lc_sensitivty value 'O',
lc_rec_type value 'U',
lc_com_type(3) value 'INT'.
"------------------------------------------------------------------
" test
"------------------------------------------------------------------
append sy-abcde to lt_messages.
append sy-abcde to lt_messages.
append sy-abcde to lt_messages.
append sy-abcde to lt_messages.
append sy-abcde to lt_messages.
append sy-abcde to lt_messages.
append sy-abcde to lt_messages.
"------------------------------------------------------------------
" anything to do ?
"------------------------------------------------------------------
if pi_recv is initial or lt_messages is initial.
return.
endif.
"------------------------------------------------------------------
" set document attributes
"------------------------------------------------------------------
ls_document_data-obj_name = pi_objn. " 'Test mail'
ls_document_data-obj_descr = pi_head. " 'E-Mail mit Anhang'
ls_document_data-obj_langu = lc_obj_langu. "VALUE 'D'.
ls_document_data-sensitivty = lc_sensitivty. "VALUE 'O'.
"------------------------------------------------------------------
" set receiver of the message
"------------------------------------------------------------------
clear lt_receiver.
ls_receiver-receiver = pi_recv.
ls_receiver-rec_type = lc_rec_type. "VALUE 'U'.
ls_receiver-com_type = lc_com_type. "VALUE 'INT'.
append ls_receiver to lt_receiver.
"------------------------------------------------------------------
"mail body
"------------------------------------------------------------------
"mail body content
refresh lt_solisti1.
append 'Sehr geehrte damen und herren' to lt_solisti1.
append space to lt_solisti1.
append 'anbei übersenden wir ihnen ' to lt_solisti1.
append 'mit freundlichen Grüssen ' to lt_solisti1.
* mail body packlist
clear ls_objpack.
clear ls_objpack-transf_bin.
ls_objpack-head_start = 0.
ls_objpack-head_num = 0.
ls_objpack-body_start = lines( lt_object_content ) + 1.
ls_objpack-body_num = lines( lt_solisti1 ).
ls_objpack-doc_type = 'RAW'.
append ls_objpack to lt_objpack.
append lines of lt_solisti1 to lt_object_content.
"------------------------------------------------------------------
"attachment
"------------------------------------------------------------------
"attachment content
refresh lt_solisti1.
lv_line_content = pi_head.
clear lv_line_content.
append lv_line_content to lt_solisti1.
loop at lt_messages into ls_message.
lv_line_content = ls_message.
append lv_line_content to lt_solisti1.
* add empty line
clear: lv_line_content.
append lv_line_content to lt_solisti1.
endloop.
append ls_document_data-obj_name to lt_solisti1.
"attachment header
ls_objhead = 'Report.TXT'.
append ls_objhead to lt_objhead .
"attachment packlist
clear ls_objpack.
clear ls_objpack-transf_bin.
ls_objpack-head_start = 1.
ls_objpack-head_num = 1.
ls_objpack-body_start = lines( lt_object_content ) + 1.
ls_objpack-body_num = lines( lt_solisti1 ).
ls_objpack-doc_type = 'RAW'.
ls_objpack-obj_name = 'ANLAGE'.
ls_objpack-obj_descr = 'Report'.
ls_objpack-doc_size = lines( lt_solisti1 ) * 255.
append ls_objpack to lt_objpack.
append lines of lt_solisti1 to lt_object_content.
"------------------------------------------------------------------
"send email
"------------------------------------------------------------------
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = ls_document_data
put_in_outbox = 'X'
commit_work = 'X'
tables
packing_list = lt_objpack
object_header = lt_objhead
* contents_bin = lt_objbin
contents_txt = lt_object_content
receivers = lt_receiver
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 ne 0.
"..................
"..................
"..................
"..................
endif.