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

Send mail with attached objects using "SOFM" objec



 
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: Fri May 23, 2008 7:55 pm    Post subject: Send mail with attached objects using "SOFM" objec Reply with quote

Code:
REPORT z_mail .
DATA: s_message TYPE sodocchgi1,
      s_list_obj TYPE solisti1 OCCURS 0,
      s_user_dats TYPE soudatai1,
      s_user TYPE soudnamei1,
      s_document TYPE sofolenti1,
      s_task_descr TYPE tline OCCURS 0,
      s_task_descr_c TYPE solisti1 OCCURS 0,
      s_object TYPE soxobj,
      s_descr_attach TYPE soattchgi1 OCCURS 0 WITH HEADER LINE,
      s_receivers TYPE somlreci1 OCCURS 0 WITH HEADER LINE.

* SAP folders of user that receive the mail.

s_user-sapname = 'DFERNANDEZ'. "(User)

CALL FUNCTION 'SO_USER_READ_API1'
     EXPORTING
          user            = s_user
     IMPORTING
          user_data       = s_user_dats
     EXCEPTIONS
          user_not_exist  = 1
          parameter_error = 2
          x_error         = 3
          OTHERS          = 4.


* Obtain Task description

CALL FUNCTION 'SWU_GET_TASK_TEXTLINES'
  EXPORTING
    task = 'TS99900015' "(Your task)
* WI_ID =
* WIHEADER =
    usage = 'W'
    linewidth = 75
    language = sy-langu
  TABLES
    ascii_text_lines = s_task_descr
* CONTAINER =
* HTML_TEXT_LINES =
  EXCEPTIONS
    wrong_usage = 1
    text_not_found = 2
    text_system_error = 3
    OTHERS = 4.

* obtain the subject message
s_message-obj_descr = 'message Subject'.

* We will create the 'text' message with the task description and the
* subject IN PRIVATE FOLDER

s_task_descr_c[] = s_task_descr[].

CALL FUNCTION 'SO_DOCUMENT_INSERT_API1'
     EXPORTING
          folder_id                  = s_user_dats-inboxfol
          document_data              = s_message
          document_type              = 'RAW'
     IMPORTING
          document_info              = s_document
     TABLES
          object_header              = s_task_descr_c
          object_content             = s_task_descr_c
     EXCEPTIONS
          folder_not_exist           = 1
          document_type_not_exist    = 2
          operation_no_authorization = 3
          parameter_error            = 4
          x_error                    = 5
          enqueue_error              = 6
          OTHERS                     = 7.

* object dats
s_object-logsys = 'SAPI'. "(your logic system)
s_object-objtype = 'BKPF'.
s_object-objkey = 'ES0100190000012002'. "(Object key)
s_object-describe = 'Description'.
s_object-method = 'DISPLAY'.

APPEND s_object TO s_list_obj.


* We write de object description
s_descr_attach-obj_descr = 'Factura'.

* Add the object to the mail.
CALL FUNCTION 'SO_ATTACHMENT_INSERT_API1'
  EXPORTING
    document_id     = s_document-doc_id
    attachment_data = s_descr_attach
    attachment_type = 'OBJ'
* IMPORTING
* ATTACHMENT_INFO =
  TABLES
    attachment_header = s_list_obj
    attachment_content = s_list_obj
* CONTENTS_HEX =
  EXCEPTIONS
    document_not_exist = 1
    attachment_type_not_exist = 2
    operation_no_authorization = 3
    parameter_error = 4
    x_error = 5
    enqueue_error = 6
    OTHERS = 7.


* Send the mail to inbox.
s_receivers-receiver = 'DFERNANDEZ'.
s_receivers-rec_type = 'B'.
s_receivers-express = 'X'.
APPEND s_receivers.

CALL FUNCTION 'SO_OLD_DOCUMENT_SEND_API1'
  EXPORTING
    document_id =  s_document-doc_id
*     PUT_IN_OUTBOX = 'X'
*     IMPORTING
*     SENT_TO_ALL =
  TABLES
    receivers = s_receivers
  EXCEPTIONS
    too_many_receiver = 1
    document_not_sent = 2
    document_not_exist = 3
    operation_no_authorization = 4
    parameter_error = 5
    x_error = 6
    enqueue_error = 7
    OTHERS = 8.

IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

* delete the document of the private folder.
CALL FUNCTION 'SO_DOCUMENT_DELETE_API1'
  EXPORTING
    document_id =  s_document-doc_id
*    UNREAD_DELETE =
*    PUT_IN_TRASH = 'X'
  EXCEPTIONS
    document_not_exist = 1
    operation_no_authorization = 2
    parameter_error = 3
    x_error = 4
    enqueue_error = 5
    OTHERS = 6.

IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
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.