Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7188964
  • 博文数量: 655
  • 博客积分: 10264
  • 博客等级: 上将
  • 技术积分: 8278
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-04 17:47
个人简介

ABAP顾问

文章分类

全部博文(655)

文章存档

2017年(2)

2014年(8)

2013年(3)

2012年(2)

2011年(18)

2010年(102)

2009年(137)

2008年(274)

2007年(134)

分类:

2008-11-27 09:50:43

*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
阅读(12003) | 评论(25) | 转发(1) |
给主人留下些什么吧!~~

chinaunix网友2009-12-25 16:18:27

请教下:如何将内表作为邮件正文的表格发送? 就是打开收件箱的邮件直观的能看到表格,感觉是发送的HTML的内容。

chinaunix网友2009-05-07 12:51:34

http://blog.chinaunix.net/u1/40527/showart.php?id=434095 注意红色字体部分

chinaunix网友2009-05-06 13:21:43

发送失败,报下面错误: 该文档的接收状态: Mail标题 发送日期: 06.05.2009 14:14:37 发送日期: icc_xxx 接收人的状态 xxx@163.com: 由于 RFC 的错误不能传输消息至节点 SMTP 请问这么回事呀。。。

chinaunix网友2008-12-29 21:43:21

了解~不过还是谢谢你回答,我再找找别的方法吧^^

qdbarry2008-12-28 20:28:54

关于发送本机文件作为附件,有个好办法,不过不说了