*FOR 470 - ECC6
REPORT z_barry_test.
DATA: 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,
i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,
v_objhead TYPE soli_tab ,
v_lines_txt TYPE i,
v_lines_bin TYPE i,
v_docchgi TYPE sodocchgi1,
v_lines_bin_all TYPE i ,
filelen TYPE i.
DATA: BEGIN OF itab_text OCCURS 0 , "内表作为邮件附件
ff1(20) ,
ff2(40) ,
ff3 TYPE i,
END OF itab_text.
START-OF-SELECTION.
itab_text-ff1 = 'skdfksd'.
itab_text-ff2 = '第一行'.
itab_text-ff3 = 123.
APPEND itab_text.
itab_text-ff1 = 'ksssd'.
itab_text-ff2 = '第二行'.
itab_text-ff3 = 456.
APPEND itab_text.
PERFORM send_mail.
*&---------------------------------------------------------------------*
*& Form send_mail
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM send_mail .
v_docchgi-obj_name = 'Text'.
v_docchgi-expiry_dat = sy-datum + 2 . "过期日期
v_docchgi-sensitivty = 'F'. "Functional object
v_docchgi-doc_size = v_lines_txt * 255.
v_docchgi-obj_descr = 'Mail标题'.
i_objtxt = 'Line1第一行'.
APPEND i_objtxt.
i_objtxt = 'Line2第二行'.
APPEND i_objtxt.
DESCRIBE TABLE i_objtxt LINES v_lines_txt.
i_objpack-transf_bin = ''.
i_objpack-head_start = 1.
i_objpack-head_num = 0.
i_objpack-body_start = 1.
i_objpack-body_num = v_lines_txt.
i_objpack-doc_type = 'RAW'.
APPEND i_objpack.
**内表作为邮件附件
DATA: tmpstr TYPE string .
CLEAR: tmpstr,i_record,i_record[].
PERFORM itabtostr TABLES itab_text USING tmpstr.
PERFORM strtorecord TABLES i_record USING tmpstr filelen.
APPEND LINES OF i_record TO i_objbin.
DESCRIBE TABLE i_record LINES v_lines_bin.
DESCRIBE TABLE i_objbin LINES v_lines_bin_all.
i_objpack-transf_bin = 'X'.
i_objpack-body_start = v_lines_bin_all - v_lines_bin + 1 .
i_objpack-body_num = v_lines_bin.
i_objpack-doc_type = 'XLS'.
i_objpack-obj_name = 'text'.
i_objpack-doc_size = v_lines_bin * 255.
CONCATENATE 'itab_attch.xls' '' INTO i_objpack-obj_descr."附件名
APPEND i_objpack.
**接收人
CLEAR i_reclist.
i_reclist-receiver = .
i_reclist-express = 'X'.
i_reclist-rec_type = 'U'.
APPEND i_reclist.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = v_docchgi
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = i_objpack
object_header = v_objhead
contents_bin = 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.
WAIT UP TO 2 SECONDS.
SUBMIT rsconn01 WITH mode = 'INT' AND RETURN.
ENDIF.
ENDFORM. " send_mail
*&---------------------------------------------------------------------*
*& Form itabtostr
*&---------------------------------------------------------------------*
FORM itabtostr TABLES intab
USING outstr TYPE string.
DATA: tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,
enter(2) TYPE c VALUE cl_abap_char_utilities=>cr_lf,
n TYPE i.
DATA: BEGIN OF headtab OCCURS 0 ,
length TYPE i ,
decimals TYPE i,
type_kind TYPE c,
name(30) TYPE c,
END OF headtab.
DATA descr_ref TYPE REF TO cl_abap_structdescr.
FIELD-SYMBOLS: TYPE abap_compdescr ,
,
TYPE ANY .
DATA:str TYPE string,
str2 TYPE string ,
text1 TYPE c.
descr_ref ?= cl_abap_typedescr=>describe_by_data( intab ).
LOOP AT descr_ref->components ASSIGNING .
MOVE-CORRESPONDING TO headtab.
APPEND headtab.
ENDLOOP.
DESCRIBE TABLE headtab LINES n.
LOOP AT intab ASSIGNING .
DO n TIMES.
ASSIGN COMPONENT sy-index OF STRUCTURE TO .
str = .
READ TABLE headtab INDEX sy-index.
IF headtab-type_kind = 'I' OR headtab-type_kind = 'P'
OR headtab-type_kind = 'F'.
SEARCH str FOR '-'.
IF sy-subrc = 0 AND sy-fdpos <> 0.
SPLIT str AT '-' INTO str text1.
CONDENSE str.
CONCATENATE '-' str INTO str.
ELSE.
CONDENSE str.
ENDIF.
ELSE.
* SHIFT str LEFT DELETING LEADING '0' .
ENDIF.
CONCATENATE str2 tab str INTO str2.
ENDDO.
SHIFT str2.
CONCATENATE outstr str2 enter INTO outstr.
CLEAR str2.
ENDLOOP.
ENDFORM. "itabtostr
*&---------------------------------------------------------------------*
*& Form strtorecord
*&---------------------------------------------------------------------*
FORM strtorecord TABLES record USING str len.
DATA:tmpbuffer TYPE xstring.
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = str
mimetype = '"text/html; charset=gb2312"'
* encoding = '8400'
IMPORTING
buffer = tmpbuffer
EXCEPTIONS
failed = 1
OTHERS = 2.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = tmpbuffer
append_to_table = ''
IMPORTING
output_length = len
TABLES
binary_tab = record.
ENDFORM. "strtorecord