leader 2022年03月09日 SAP 150 0
*& Report  ZRICO_TEST4 
report zrico_test4. 
  gc_tab  type c value cl_bcs_convert=>gc_tab,  "CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB 
  gc_crlf type c value cl_bcs_convert=>gc_crlf. "CL_ABAP_CHAR_UTILITIES=>CR_LF 
parameters:  mailto type ad_smtpadr default ''. " 收件人 
data send_request   type ref to cl_bcs. 
data document       type ref to cl_document_bcs. 
data recipient      type ref to if_recipient_bcs. 
data bcs_exception  type ref to cx_bcs. 
data main_text      type bcsy_text. 
data binary_content type solix_tab. 
data size           type so_obj_len. 
data sent_to_all    type os_boolean. 
  perform create_content. 
  perform send. 
*&      Form  create_content 
* Create Example Content 
* 1) Write example text into a string 
* 2) convert this string to solix_tab 
form create_content. 
  data lv_string type string. 
  data ls_t100   type t100. 
* -------------------------------------------------------------- 
* as example content we use some system messages out of t100 
* get them for all installed languages from db 
* and write one line for each language into the spread sheet 
* columns are separated by TAB and each line ends with CRLF 
  concatenate '测试!' 
              gc_crlf gc_crlf 
              into lv_string. 
  do 10 times. 
    concatenate lv_string 
                '1111111111111111111111111111111111111111111111111111111111111' gc_tab 
                '2222222222222222222222222222222222222222222222222222222222222' gc_tab 
                '3333333333333333333333333333333333333333333333333333333333333' gc_tab 
                'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' gc_tab 
                'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' gc_tab 
                'ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc' gc_tab 
                'ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd' gc_tab 
                'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' gc_tab 
                'fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff' gc_tab 
                'ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg' gc_tab 
                'hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh' gc_tab 
                'iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii' gc_tab 
                'jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj' gc_tab 
                'kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk' gc_crlf 
                into lv_string. 
* -------------------------------------------------------------- 
* convert the text string into UTF-16LE binary data including 
* byte-order-mark. Mircosoft Excel prefers these settings 
* all this is done by new class cl_bcs_convert (see note 1151257) 
          iv_string   = lv_string 
          iv_codepage = '4103'  "suitable for MS Excel, leave empty 
          iv_add_bom  = 'X'     "for other doc types 
          et_solix  = binary_content 
          ev_size   = size ). 
    catch cx_bcs. 
      message e445(so). 
endform.                    "create_content 
* UTF-16LE including the BOM (Byte order mark) 
* is preferred by Microsoft Excel. If you want to create 
* other binary content you may choose another codepage (e.g. 
* '4110' (UTF-8) which is standard for e-mails). 
* Find SAP codepage names in the drop down list 
* for the codepage setting of node SMTP in transaction SCOT. 
* Or: leave iv_codepage and iv_add_bom empty. Then the target 
* codepage is set according to SAPconnect settings 
* Important: 
* SAP neither guarantees that the attachment created 
* by this report can be opened by all Excel Versions nor 
* that it can be opened by any 3rd party software at all 
*&      Form  send 
form send. 
*     -------- create persistent send request ------------------------ 
      send_request = cl_bcs=>create_persistent( ). 
*     -------- create and set document with attachment --------------- 
*     create document object from internal table with text 
      append 'Hello world!' to main_text.                   " 邮件内容 
      document = cl_document_bcs=>create_document( 
        i_type    = 'RAW' 
        i_text    = main_text 
        i_subject = 'Test Created By ricochen' ).      " 邮件主题名 
*     add the spread sheet as attachment to document object 
        i_attachment_type    = 'xls'                        " 附件格式 
        i_attachment_subject = 'ExampleSpreadSheet'         " attachment name 
        i_attachment_size    = size                         "附件大小 
        i_att_content_hex    = binary_content ).            "附件内容 
*     add document object to send request 
      send_request->set_document( document ). 
*     --------- add recipient (e-mail address) ----------------------- 
*     create recipient object 
      recipient = cl_cam_address_bcs=>create_internet_address( mailto ). 
*     add recipient object to send request 
      send_request->add_recipient( recipient ). 
*      recipient = cl_cam_address_bcs=>create_internet_address( '' ). 
*      send_request->add_recipient( recipient ). 
*     ---------- send document --------------------------------------- 
      sent_to_all = send_request->send( i_with_error_screen = 'X' ). 
      commit work. 
      wait up to 2 seconds. 
      submit rsconn01 with mode = 'INT' 
                    with output = '' 
                    and return. 
      if sent_to_all is initial. 
        message i500(sbcoms) with mailto. 
        message s022(so). 
*   ------------ exception handling ---------------------------------- 
*   replace this rudimentary exception handling with your own one !!! 
    catch cx_bcs into bcs_exception. 
      message i865(so) with bcs_exception->error_type. 
endform.                    "send


微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!