Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Mail using ABAP

Former Member
0 Kudos

Hi all,

What is mail using ABAP?

Please can u send me this program for mail using ABAP...

Reply me soon,

Thx,

S.Suresh.

1 ACCEPTED SOLUTION

venkat_o
Active Contributor
0 Kudos

Suresh selvarajan, Check the following Sample program. Wherever you find mai that is mail . i could not post with that word.

REPORT  zvenkat_mai_simple.
*--------------------------------------------------------*
*  mai related declarations
*--------------------------------------------------------*
"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_mai(99) TYPE c.
*--------------------------------------------------------*
"start-of-selection.
*--------------------------------------------------------*
START-OF-SELECTION.

  PERFORM send_mai.

*&---------------------------------------------------------------------*
  "Form  send_mai
  "---------------
  " PACKING LIST table requires information about how the data in the
  " tables OBJECT_HEADER, CONTENTS_BIN and CONTENTS_TXT are to be
  " distributed to the documents and its attachments. The first row is
  " for the document, the following rows are each for one attachment.
*&---------------------------------------------------------------------*
FORM send_mai .

  "Subject of the mai.
  w_document_data-obj_name  = 'MAI_TO_HEAD'.
  w_document_data-obj_descr = 'Simple mai using SAP ABAP'.

  "Body of the mai
  PERFORM build_body_of_mai
    USING:space,
          'Hi,',
          'I am fine. How are you? How are you doing ? ',
          'This program has been created to send simple mai',
          'with Subject,Body with Address of the sender. ',
          'Thanks and Regards,',
          'Venkat.O,',
          'SAP HR Technical Consultant.'.

  "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_mai.
  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 mai 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 'mai has been Successfully Sent.'.
  ELSE.
    WAIT UP TO 2 SECONDS.
    SUBMIT rsconn01 WITH mode = 'INT'
                 WITH output = 'X'
                 AND RETURN.
  ENDIF.

ENDFORM.                    " send_mai
*&---------------------------------------------------------------------*
"      Form  build_body_of_mai
*&---------------------------------------------------------------------*
FORM build_body_of_mai  USING l_message.

  w_body_msg = l_message.
  APPEND w_body_msg TO i_body_msg.
  CLEAR  w_body_msg.

ENDFORM.                    " build_body_of_mai
Regards, Venkat.O

3 REPLIES 3

venkat_o
Active Contributor
0 Kudos

Suresh selvarajan, Check the following Sample program. Wherever you find mai that is mail . i could not post with that word.

REPORT  zvenkat_mai_simple.
*--------------------------------------------------------*
*  mai related declarations
*--------------------------------------------------------*
"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_mai(99) TYPE c.
*--------------------------------------------------------*
"start-of-selection.
*--------------------------------------------------------*
START-OF-SELECTION.

  PERFORM send_mai.

*&---------------------------------------------------------------------*
  "Form  send_mai
  "---------------
  " PACKING LIST table requires information about how the data in the
  " tables OBJECT_HEADER, CONTENTS_BIN and CONTENTS_TXT are to be
  " distributed to the documents and its attachments. The first row is
  " for the document, the following rows are each for one attachment.
*&---------------------------------------------------------------------*
FORM send_mai .

  "Subject of the mai.
  w_document_data-obj_name  = 'MAI_TO_HEAD'.
  w_document_data-obj_descr = 'Simple mai using SAP ABAP'.

  "Body of the mai
  PERFORM build_body_of_mai
    USING:space,
          'Hi,',
          'I am fine. How are you? How are you doing ? ',
          'This program has been created to send simple mai',
          'with Subject,Body with Address of the sender. ',
          'Thanks and Regards,',
          'Venkat.O,',
          'SAP HR Technical Consultant.'.

  "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_mai.
  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 mai 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 'mai has been Successfully Sent.'.
  ELSE.
    WAIT UP TO 2 SECONDS.
    SUBMIT rsconn01 WITH mode = 'INT'
                 WITH output = 'X'
                 AND RETURN.
  ENDIF.

ENDFORM.                    " send_mai
*&---------------------------------------------------------------------*
"      Form  build_body_of_mai
*&---------------------------------------------------------------------*
FORM build_body_of_mai  USING l_message.

  w_body_msg = l_message.
  APPEND w_body_msg TO i_body_msg.
  CLEAR  w_body_msg.

ENDFORM.                    " build_body_of_mai
Regards, Venkat.O

Former Member
0 Kudos

Hi Suresh,

  • Send MESSAGE

maildata-obj_name = 'TEST'.

maildata-obj_descr = 'Test Subject'.

loop at htmllines.

mailtxt = htmllines.

append mailtxt.

endloop.

mailrec-receiver = 'ID'.

mailrec-rec_type = 'U'.

append mailrec.

call function 'SO_NEW_DOCUMENT_SEND_API1'

exporting

document_data = maildata

document_type = 'HTM'

put_in_outbox = 'X'

tables

object_header = mailtxt

object_content = mailtxt

receivers = mailrec

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 SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

Kindly Reward Points If You Found The Reply Helpful,

Cheers,

Chaitanya.

Former Member
0 Kudos

Hi,

SAP is a robust system, which gives many facilities in the form of Function Modules (FMs) for connecting to external systems or for use within the system. With a clever use of these FMs we can achieve a lot of things through ABAP code.

Firstly SAP Mail

A SAP mail is a mail internal to the SAP system. It is a very good forum to exchange information with other users. Using a SAP mail in ABAP code facilitates exchange of automatic messages at various stages of the business process. It is easy to use and saves many hassles involved in using workflows for exchanging messages.

Sending Email to a non-SAP system:

Though SAP mail is a very robust method of interacting with users within SAP system, it is always good to receive email in Microsoft inbox. This also works like an additional notification to users in case they do not check SAP mail regularly.

Sending an email to the Microsoft Inbox is a way of interacting with a non SAP system through ABAP code and hence is very interesting. A fair knowledge of UNIX shell scripting is assumed here.

Please refer to the link below:

http://www.sapdev.co.uk/reporting/email/emailhome.htm

http://www.sap-img.com/fu016.htm

http://www.thespot4sap.com/Articles/SAP_Mail_UNIX.asp

Reward Points if found helpfull..

Cheers,

Chandra Sekhar.