注册 登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

黑山老妖的博客

 
 
 

日志

 
 
关于我

主要用来存放收集的资料,几乎都是转贴的东西!感谢原作者!

PDF & EMAIL  

2008-03-26 14:30:09|  分类: ABAP |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

*&---------------------------------------------------------------------*
*& Report  Z_SEND_MAIL_ATTACHMENT
*&
*&---------------------------------------------------------------------*
*& test attachment
*&
*&---------------------------------------------------------------------*
REPORT  Z_SEND_MAIL_ATTACHMENT.
*  Send document with OTF/ALI attachment from spool to external
*  recipient. OTF/ALI document is converted to PDF/HTML format during
*  the SAPconnect send process.
*  This report serves as example documentation for the function
*  modules SO_NEW_DOCUMENT_ATT_SEND_API1 and SO_DOCUMENT_SEND_API1.
*  Following this example you should be able to develop your own
*  report to send documents with all kinds of attachments.
*  Creation of the entry for the compressed document

* Data Declaration
Data: docdata    like sodocchgi1,
      objpack    like sopcklsti1 occurs  1 with header line,
      objhead    like solisti1   occurs  1 with header line,
      objtxt     like solisti1   occurs 10 with header line,
      objbin     like solisti1   occurs 10 with header line,
      objhex     like solix      occurs 10 with header line,
      reclist    like somlreci1  occurs  1 with header line.
OBJBIN = '  |  '. APPEND OBJBIN.
OBJPACK-HEAD_START = 1.
Data: listobject like abaplist   occurs  1 with header line.
Data: tab_lines  type i,
      doc_size   type i,
      att_type   like SOODK-OBJTP.

data method1 like sy-ucomm.
data g_user like soudnamei1.
data g_user_data like soudatai1.
data g_owner like soud-usrnam.
data g_receipients like soos1 occurs 0 with header line.
data g_document like sood4 .
data g_header like sood2 occurs 0 with header line.
data g_folmam like sofm2.
data g_objcnt like soli occurs 0 with header line.
data g_objhead like soli occurs 0 with header line.
data g_objpara  like selc occurs 0 with header line.
data g_objparb  like soop1 occurs 0 with header line.
data g_attachments like sood5 occurs 0 with header line.
data g_references like soxrl occurs 0 with header line.

data g_authority like sofa-usracc.
data g_ref_document like sood4.
data g_new_parent like soodk.
data: begin of g_files occurs 10 ,
      text(4096) type c,
   end of g_files.

data : fold_number(12) type c,
       fold_yr(2) type c,
       fold_type(3) type c.

Tables: Mara.

data: begin of Z_mara occurs 0,
      matnr like mara-matnr,
      mtart like mara-mtart,
      meins like mara-meins,
      end of Z_mara.

Top-of-page.
  Write : 'Material Number', '    ','Material Type', '     ','UOM'.

START-OF-SELECTION.

  z_mara-matnr = 'Material Number'.
  z_mara-mtart = 'Material Type'.
  z_mara-meins = 'UOM'.
  append z_mara.

  select matnr mtart meins from mara into table z_mara where matnr like
    '100%'.
  DESCRIBE TABLE OBJBIN LINES TAB_LINES.

  OBJPACK-HEAD_START = 1.

* NOTE: Create ALI/OTF Document in Spool
*   ALI Document can be created by displaying a list and selecting
*   menue System -> List -> Print (only put to Spool).
*   OTF Document can be created running report SF_EXAMPLE_01 in
*   system.
*   Example used here:
*   create list in memory

  submit Z_MAIL_ATTACHMENT exporting list to memory and return.

*   and read list from memory into table

  CALL FUNCTION 'LIST_FROM_MEMORY'
    TABLES
      listobject = listobject
    EXCEPTIONS
      OTHERS     = 1.

  IF sy-subrc <> 0.
    message ID '61' TYPE 'E' NUMBER '731'
    with 'LIST_FROM_MEMORY'.
  ENDIF.
**       PACKING_LIST = OBJPACK .
**       Because listobject is of size RAW(1000)
**       and objbin     is of size CHAR(255) we make this table copy

  CALL FUNCTION 'TABLE_COMPRESS'
*     IMPORTING
*       COMPRESSED_SIZE       =
    TABLES
       IN                    = listobject
       OUT                   = objbin
    EXCEPTIONS
       OTHERS                = 1.
*    if sy-subrc <> 0.
*      message ID '61' TYPE 'E' NUMBER '731'
*      with 'TABLE_COMPRESS'.
*    endif.
**      ELSE.
* NOTE: Creation of attachment is finished yet.
*   For your report, the attachment should be placed into table
*     objtxt for plain text or
*     objbin for binary content.
*   Now create the message and send the document.
*             'of recipients'.
* Create Message Body
*   Title and Description

*  docdata-obj_name  = 'TEST_ALI'.
  docdata-obj_name  = 'TEST_OTF'.
  docdata-obj_descr = 'Test including ALI/HTML Attachment'.
*   Main Text
  objtxt = 'Test Document.'.
  append objtxt.
  objtxt = 'You will find an ALI/HTML attachment in this message.'.
  append objtxt.
  objtxt = 'Have a nice day.'.
  append objtxt.
*   Write Packing List (Main)
  describe table objtxt lines tab_lines.
  read     table objtxt index tab_lines.
  docdata-doc_size = ( tab_lines - 1 ) * 255 + strlen( objtxt ).
  clear objpack-transf_bin.
  objpack-head_start = 1.
  objpack-head_num   = 0.
  objpack-body_start = 1.
  objpack-body_num   = tab_lines.
  objpack-doc_type   = 'RAW'.
  append objpack.
* Create Message Attachment
*   Write Packing List (Attachment)
*  att_type = 'ALI'.
  att_type = 'OTF'.
  describe table objbin lines tab_lines.
*    describe table z_mara lines tab_lines.

  read     table objbin index tab_lines.
*    read     table z_mara index tab_lines.

  objpack-doc_size = ( tab_lines - 1 ) * 255 + strlen( objbin ).
  objpack-transf_bin = 'X'.
  objpack-head_start = 1.
  objpack-head_num   = 0.
  objpack-body_start = 1.
  objpack-body_num   = tab_lines.
  objpack-doc_type   = att_type.
  objpack-obj_name   = 'ATTACHMENT'.
  objpack-obj_descr  = 'Attached Document'.
  append objpack.


* Create receiver list
*  reclist-receiver = 'michael@163.com'.  "      <-- change address
*  reclist-rec_type = 'U'.
*  append reclist.
*  reclist-rec_type = 'U'.
*  append reclist.
*  reclist-receiver = sy-uname.                " <-- change internal user
*  reclist-rec_type = 'B'.
*  append reclist.

* Send Message
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data                     = docdata
      PUT_IN_OUTBOX                    = 'X'
      COMMIT_WORK                      = 'X'     "used from rel. 6.10
*   IMPORTING
*     SENT_TO_ALL                       =
*     NEW_OBJECT_ID                     =
    tables
      packing_list                      = objpack
      OBJECT_HEADER                     = objhead
      CONTENTS_BIN                      = objbin
      CONTENTS_TXT                      = objtxt
*     CONTENTS_HEX                      = objhex
*     OBJECT_PARA                       =
*     OBJECT_PARB                       =
      receivers                         = 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.
    message ID 'SO' TYPE 'S' NUMBER '023'
            with docdata-obj_name.
  ENDIF.
  write: / 'End of Program'.

  评论这张
 
阅读(345)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018