Sunday, December 19, 2010
REPORT  zvenkat_mail_simple.
"Variables
DATA :
    g_sent_to_all   TYPE sonv-flag,
    g_tab_lines     TYPE i.
"Types
TYPES:
    t_document_data  TYPE  sodocchgi1,
    t_packing_list   TYPE  sopcklsti1,
    t_attachment     TYPE  solisti1,
    t_body_msg       TYPE  solisti1,
    t_receivers      TYPE  somlreci1.
"Workareas
DATA :
    w_document_data  TYPE  t_document_data,
    w_packing_list   TYPE  t_packing_list,
    w_attachment     TYPE  t_attachment,
    w_body_msg       TYPE  t_body_msg,
    w_receivers      TYPE  t_receivers.
"Internal Tables
DATA :
    i_document_data  TYPE STANDARD TABLE OF t_document_data,
    i_packing_list   TYPE STANDARD TABLE OF t_packing_list,
    i_attachment     TYPE STANDARD TABLE OF t_attachment,
    i_body_msg       TYPE STANDARD TABLE OF t_body_msg,
    i_receivers      TYPE STANDARD TABLE OF t_receivers.
PARAMETERS:p_mail TYPE char120.
"start-of-selection.

START-OF-SELECTION.
  "Subject of the mail.
  w_document_data-obj_name  = 'MAIL_TO_HEAD'.
  w_document_data-obj_descr = 'Simple mail using SAP ABAP'.
  "Body of the mail
  w_body_msg = 'Hi,'.
  APPEND w_body_msg TO i_body_msg.
  CLEAR  w_body_msg.

  w_body_msg = 'This is body of the mail.'.
  APPEND w_body_msg TO i_body_msg.
  CLEAR  w_body_msg.

  "Write Packing List (Body)
  DESCRIBE TABLE i_body_msg LINES g_tab_lines.
  w_packing_list-head_start = 1.
  w_packing_list-head_num   = 0.
  w_packing_list-body_start = 1.
  w_packing_list-body_num   = g_tab_lines.
  w_packing_list-doc_type   = 'RAW'.
  APPEND w_packing_list TO i_packing_list.
  CLEAR  w_packing_list.

  "Fill the document data and get size of attachment
  READ TABLE i_body_msg INTO w_body_msg INDEX g_tab_lines.
  w_document_data-doc_size = ( g_tab_lines - 1 ) * 255 + STRLEN( w_body_msg ).
  "Receivers List.
  w_receivers-rec_type   = 'U'.     "Internet address
  w_receivers-receiver   = p_mail.
  w_receivers-com_type   = 'INT'.
  w_receivers-notif_del  = 'X'.
  w_receivers-notif_ndel = 'X'.
  APPEND w_receivers TO i_receivers .
  CLEAR:w_receivers.

  "Function module to send mail to Recipients
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = w_document_data
      put_in_outbox              = 'X'
      commit_work                = 'X'
    IMPORTING
      sent_to_all                = g_sent_to_all
    TABLES
      packing_list               = i_packing_list
      contents_txt               = i_body_msg
      receivers                  = i_receivers
    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 i303(me) WITH 'Mail has been Successfully Sent.'.
  ELSE.
    WAIT UP TO 2 SECONDS.
    SUBMIT rsconn01 WITH mode = 'INT' WITH output = 'X' AND RETURN.
  ENDIF.

0 comments:

Post a Comment

Your useful comments, suggestions are appreciated.Your comments are moderated.

Followers

Contact Form

Name

Email *

Message *

Web Dynpro ABAP Book

An SAP Consultant

Follow US


Want to Contribute ?

If you are interested in writing about the new stuff you learn everyday while working, please write to the.sap.consultants@gmail.com.

Click on Contribution for more details.