SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Отправка по почте результатов отчета в сжатом виде.



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Programming Techniques | Приемы программирования -> Mail
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Wed Jan 23, 2008 10:31 am    Post subject: Отправка по почте результатов отчета в сжатом виде. Reply with quote

Программа иллюстрирует получение листа, сформированного другим отчетом в памяти, получение листа из памяти, сжатие и отправку на e-mail по таблице получателей.

Code:

*&---------------------------------------------------------------------*
*& Report ZSSO_DOCUMENT_SEND_API1
*&
*&---------------------------------------------------------------------*
*& Send document with OTF/ALI attachment from spool to external reci-
*& pient. OTF/ALI document is converted to PDF/HTML format during the
*& SAPconnect send process.
*&
*&---------------------------------------------------------------------*

*** Data Declaration ***
* Mail recepient's table
TABLES ZESAPUSERS.

DATA: BEGIN OF WA_ZESAPUSERS OCCURS 10,
       USNAME LIKE ZESAPUSERS-USNAME,
       BUKRS  LIKE ZESAPUSERS-BUKRS,
     END OF WA_ZESAPUSERS.

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,
      reclist LIKE somlreci1 occurs 1 with header line.

DATA:
  listobject  LIKE abaplist occurs 1 with header line.

DATA:
  tab_lines   TYPE i,
  doc_size    TYPE i,
  att_type    LIKE SOODK-OBJTP.

DATA: begin of X occurs 0.
 include structure VKDFS.
DATA: end of X.

* 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_REPORT_NAME
    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.

* Because listobject is of size RAW(1000)
* and objbin is of size CHAR(255) we make this table copy
  CALL FUNCTION 'TABLE_COMPRESS'
    TABLES
      IN     = listobject
      OUT    = objbin
    EXCEPTIONS
      OTHERS = 1.

  if sy-subrc <> 0.
    message ID '61' TYPE 'E' NUMBER '731'
    with 'TABLE_COMPRESS'.
  endif.

* 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.
* Create Message Body

* Title and Description
  docdata-obj_name = 'TEST_ALI'(M01).
  docdata-obj_descr =
    'Message including invoice list in ALI Attachment'(M02).
  objtxt = 'Invoice list.'(M03).
  append objtxt.

  objtxt = 'You will find an ALI attachment in this message.'(M04).
  append objtxt.

  objtxt = 'Have a nice day.'(M05).
  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'(M06).
  append objpack.

*   Create Message Attachment
*   Write Packing List (Attachment)
  att_type = 'ALI'(M07).
  describe table objbin lines tab_lines.
  read table objbin 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'(M08).
  objpack-obj_descr = 'Attached Document'(M09).
  append objpack.

  SELECT * INTO CORRESPONDING FIELDS OF TABLE WA_ZESAPUSERS FROM
  ZESAPUSERS.

  if sy-subrc = 0.
   LOOP AT WA_ZESAPUSERS .
    reclist-receiver = WA_ZESAPUSERS-USNAME.
    reclist-rec_type = 'B'."SAP user
    append reclist.
   ENDLOOP.
  endif.

  IF sy-subrc <> 0.
     message ID 'SO' TYPE 'S' NUMBER '054'
     with ZESAPUSERS-USNAME.
  ENDIF.

* Send Message
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data = docdata
      PUT_IN_OUTBOX = 'X'
    TABLES
      packing_list  = objpack
      OBJECT_HEADER = objhead
      CONTENTS_BIN  = objbin
      CONTENTS_TXT  = objtxt
      receivers     = reclist
    EXCEPTIONS
      OTHERS = 8.

  IF sy-subrc <> 0.
    message ID 'SO' TYPE 'S' NUMBER '023'
    with docdata-obj_name.
  ENDIF.

  WRITE: / 'End of Program'(M10).
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Programming Techniques | Приемы программирования -> Mail All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.