FUNCTION zcrm_send_email_and_attach . *"---------------------------------------------------------------------- *"*"Local Interface: *" IMPORTING *" VALUE(IV_TITLE) TYPE STRING OPTIONAL *" VALUE(IV_HEADER) TYPE STRING OPTIONAL *" VALUE(IV_BODY) TYPE STRING OPTIONAL *" VALUE(IT_TABLE) TYPE ANY TABLE OPTIONAL *" EXPORTING *" VALUE(ES_ZCRMS_MESSAGE) TYPE ZCRMS_MESSAGE *" TABLES *" IT_RECLIST STRUCTURE SOMLRECI1 OPTIONAL *"---------------------------------------------------------------------- ***数据定义 FIELD-SYMBOLS: <fs_comp> TYPE abap_compdescr, <fs_value> TYPE any, <fs_line> TYPE any, <fs_col> TYPE any. ***fill_text CLEAR:gs_solisti1. REFRESH:gt_solisti1. gs_solisti1 = '<head>'. APPEND gs_solisti1 TO gt_solisti1. gs_solisti1 = '</head>'. APPEND gs_solisti1 TO gt_solisti1. gs_solisti1 = '<body>'. APPEND gs_solisti1 TO gt_solisti1. IF iv_header IS NOT INITIAL. CONCATENATE '<h3>' iv_header '</h3>' INTO gs_solisti1. APPEND gs_solisti1 TO gt_solisti1. ENDIF. gs_solisti1 = '<table border="0">'. APPEND gs_solisti1 TO gt_solisti1. IF iv_body IS NOT INITIAL. gs_solisti1 = '<tr>'. APPEND gs_solisti1 TO gt_solisti1. gs_solisti1 = iv_body. APPEND gs_solisti1 TO gt_solisti1. gs_solisti1 = '</tr>'. APPEND gs_solisti1 TO gt_solisti1. ENDIF. gs_solisti1 = '<table border="1">'. APPEND gs_solisti1 TO gt_solisti1. gs_solisti1 = '<tr>'. APPEND gs_solisti1 TO gt_solisti1. REFRESH:gt_dd03t,gt_ddfields. CLEAR:gv_tablesize,gv_check. IF it_table IS NOT INITIAL. LOOP AT it_table ASSIGNING <gs_line>. gr_cl_abap_structdescr ?= cl_abap_typedescr=>describe_by_data( <gs_line> ). *表头 IF gt_ddfields[] IS INITIAL. CALL METHOD gr_cl_abap_structdescr->get_ddic_field_list EXPORTING p_langu = sy-langu RECEIVING p_field_list = gt_ddfields EXCEPTIONS not_found = 1 no_ddic_type = 2 OTHERS = 3. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. ENDIF. IF gv_check = abap_false. CLEAR:gs_solisti1. LOOP AT gt_ddfields INTO gs_ddfields. IF gs_solisti1 IS INITIAL. CONCATENATE '<td>' gs_ddfields-fieldtext '</td>' INTO gs_solisti1. ELSE. CONCATENATE gs_solisti1 '<td>' gs_ddfields-fieldtext '</td>' INTO gs_solisti1. ENDIF. gv_check = abap_true. gv_tablesize = gv_tablesize + gs_ddfields-leng. ENDLOOP. APPEND gs_solisti1 TO gt_solisti1. ENDIF. *表内容 gs_solisti1 = '<tr>'. LOOP AT gr_cl_abap_structdescr->components ASSIGNING <fs_comp>. ASSIGN <fs_comp>-name TO <fs_col>. ASSIGN COMPONENT <fs_col> OF STRUCTURE <gs_line> TO <gs_field>. WRITE <gs_field> TO gv_field. CONCATENATE gs_solisti1 '<td >' gv_field '</td> ' INTO gs_solisti1. ENDLOOP. APPEND gs_solisti1 TO gt_solisti1. gs_solisti1 = '</tr>'. APPEND gs_solisti1 TO gt_solisti1. ENDLOOP. ENDIF. gs_solisti1 = '</table>'. APPEND gs_solisti1 TO gt_solisti1. gs_solisti1 = '</table>'. APPEND gs_solisti1 TO gt_solisti1. ***fill_object_details CLEAR:gv_strlen. DESCRIBE TABLE gt_solisti1 LINES gv_strlen. READ TABLE gt_solisti1 INTO gs_solisti1 INDEX gv_strlen. CLEAR:gs_sodocchgi1. REFRESH:gt_sopcklsti1. gs_sodocchgi1-obj_name = 'SAPCRM'. gs_sodocchgi1-obj_descr = iv_title. gs_sodocchgi1-sensitivty = 'F'. gs_sodocchgi1-obj_langu = sy-langu. gs_sodocchgi1-doc_size = ( gv_strlen - 1 ) * 255 + strlen( gs_solisti1 ). CLEAR gs_sopcklsti1-transf_bin. gs_sopcklsti1-head_start = 1. gs_sopcklsti1-head_num = 0. gs_sopcklsti1-body_start = 1. gs_sopcklsti1-body_num = gv_strlen. gs_sopcklsti1-doc_type = 'HTM'. APPEND gs_sopcklsti1 TO gt_sopcklsti1. ****Define Attachment ****EXCEL附加抬头 CLEAR:gv_string,gv_lines,gv_number. DESCRIBE TABLE gt_ddfields LINES gv_lines. LOOP AT gt_ddfields INTO gs_ddfields. gv_number = gv_number + 1. IF gv_lines = gv_number. CONCATENATE gv_string gs_ddfields-fieldtext gc_crlf INTO gv_string. ELSE. IF gv_string IS INITIAL. CONCATENATE gs_ddfields-fieldtext gc_tab INTO gv_string. ELSE. CONCATENATE gv_string gs_ddfields-fieldtext gc_tab INTO gv_string. ENDIF. ENDIF. ENDLOOP. ****EXCEL附加内容 LOOP AT it_table ASSIGNING <gs_line>. gr_cl_abap_structdescr ?= cl_abap_typedescr=>describe_by_data( <gs_line> ). CLEAR:gv_number. LOOP AT gr_cl_abap_structdescr->components ASSIGNING <fs_comp>. gv_number = gv_number + 1. ASSIGN <fs_comp>-name TO <fs_col>. ASSIGN COMPONENT <fs_col> OF STRUCTURE <gs_line> TO <gs_field>. WRITE <gs_field> TO gv_field. IF gv_lines = gv_number. CONCATENATE gv_string gv_field gc_crlf INTO gv_string. ELSE. CONCATENATE gv_string gv_field gc_tab INTO gv_string. ENDIF. ENDLOOP. ENDLOOP. * Convert string to xstring type * 'APPLICATION/MSEXCEL;charset=utf-16le' CLEAR:gv_xstring. CALL FUNCTION 'SCMS_STRING_TO_XSTRING' EXPORTING text = gv_string mimetype = gc_mimetype IMPORTING buffer = gv_xstring EXCEPTIONS failed = 1 OTHERS = 2. * Add the file header for utf-16le. . IF sy-subrc = 0. CONCATENATE cl_abap_char_utilities=>byte_order_mark_little gv_xstring INTO gv_xstring IN BYTE MODE. ENDIF. CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' EXPORTING buffer = gv_xstring TABLES binary_tab = gt_solix. ***计算附件大小分配空间******************* DESCRIBE TABLE it_table LINES gv_lines. gv_lines = gv_lines * 2. gs_sopcklsti1-transf_bin = 'X'. gs_sopcklsti1-head_start = 1. gs_sopcklsti1-head_num = 0. gs_sopcklsti1-body_start = 1. gs_sopcklsti1-body_num = gv_lines + 1. gs_sopcklsti1-doc_type = 'xls'. gs_sopcklsti1-obj_name = 'ATTACHMENT'. gs_sopcklsti1-obj_descr = iv_title. gs_sopcklsti1-doc_size = gs_sopcklsti1-body_num * gv_tablesize * gv_lines . *gv_tablesize APPEND gs_sopcklsti1 TO gt_sopcklsti1. ***SO_DOCUMENT_SEND_API1邮件函数 CALL FUNCTION 'SO_DOCUMENT_SEND_API1' EXPORTING document_data = gs_sodocchgi1 put_in_outbox = '' commit_work = 'X' TABLES packing_list = gt_sopcklsti1 * OBJECT_HEADER = * CONTENTS_BIN = contents_txt = gt_solisti1 contents_hex = gt_solix * OBJECT_PARA = * OBJECT_PARB = receivers = it_reclist * ET_VSI_ERROR = 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. es_zcrms_message-type = gc_s. es_zcrms_message-message = text-001."'Message sent successfully!'. * Implement suitable error handling here "立即发送 SUBMIT rsconn01 WITH mode = 'INT' * with output = 'X' AND RETURN. * MESSAGE s001(00) WITH 'Message sent successfully!'. ELSE. es_zcrms_message-type = gc_e. es_zcrms_message-message = text-002."'Message sent failure!'. ENDIF. ENDFUNCTION.
SO_DOCUMENT_SEND_API1可以指定发件人,SO_NEW_DOCUMENT_ATT_SEND_API1不可以。
SENDER_ADDRESS = XXXX@XXX.COM
SENDER_ADDRESS_TYPE = INT
^_^很多人都把资料锁进了note里,以后还怎么百度呢^_^