Showing posts with label message. Show all posts
Showing posts with label message. Show all posts

Thursday, November 23, 2017

Send Message or Email to Internal or External User

In the previous post, I showed how to send a very simple message to another logged on user in SAP, hence if the user is not logged in, he/she will not get the message. Here I will introduce another function module known as SO_NEW_DOCUMENT_SEND_API1 to send email to internal SAP user or External user as an email.

REPORT  y_evan_email.

DATA : maildata TYPE sodocchgi1.
DATA : mailtxt TYPE TABLE OF solisti1 WITH HEADER LINE. " To store message
DATA : mailrec TYPE TABLE OF somlreci1 WITH HEADER LINE. "To store receiver

START-OF-SELECTION.
  CLEAR : maildata, mailtxt, mailrec.

  REFRESH:mailtxt, mailrec.

  maildata-obj_name = 'message1'.
  maildata-obj_descr = 'This is not urgent, just Testing'. "Subject
  maildata-obj_langu = sy-langu.

  mailtxt-line = 'Hello World, I am Message 1'.
  APPEND mailtxt.

  maildata-obj_name = 'message2'.
  maildata-obj_langu = sy-langu.

  mailtxt-line = 'And this is message 2'.
  APPEND mailtxt.

"Send to external
  mailrec-receiver = 'evan.christiawan@mail.co.id'.
*  mailrec-COPY = 'X'. "Set as CC
*  mailrec-BLIND_COPY = 'X'.  "Set as BCC
  mailrec-NOTIF_READ = 'X'.
  mailrec-rec_type = 'U'. "Use if it is an external mail
  APPEND mailrec.

"Send to internal
  mailrec-receiver = 'SOL_EVAN'.
*  mailrec-COPY = 'X'. "CC
*  mailrec-BLIND_COPY = 'X'.  "BCC
*  mailrec-NO_FORWARD = 'X'.
  mailrec-no_print = 'X'.
*  mailrec-to_answer = 'X'.
  mailrec-EXPRESS = 'X'. "Show pop up notification
  mailrec-NOTIF_READ = 'X'.
  APPEND mailrec.

  CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
    EXPORTING
  document_data = maildata
  document_type = 'RAW'
  put_in_outbox = ' '
  commit_work = 'X'
*   IP_ENCRYPT                       =
*   IP_SIGN                          =
* IMPORTING
*   SENT_TO_ALL                      =
*   NEW_OBJECT_ID                    =
    TABLES
   OBJECT_HEADER                    = mailtxt
   OBJECT_CONTENT                   = mailtxt
*   CONTENTS_HEX                     =
*   OBJECT_PARA                      =
*   OBJECT_PARB                      =
      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.


The following sample program will create a message based on table mailtxt and will send it to the receiver referencing table mailrec. You can change the attribute of the receiver to set whether it is a CC or BCC, etc. But i will show the main difference for the internal and external receiver which is the rec_type attribute. This attribute need to be set as 'U' to tell SAP that the receiver is external.

Here is the Sample Output from the above code:

External / Email



Internal

- Get Notification if express attribute in the mailrec is checked

- Received the message on tcode SO01





Send Popup Message to Other User in SAP

In this post, i will show 1 FM that might be useful for us in SAP to Send a simple Popup Message to Another Logged on User in SAP.
  1. Function Module 'th_popup' in SE37
  2. Fill in the Client, Receiver User, and the Message
  3. Execute (F8)