Monday, February 20, 2017

Sending Email with 'SO_NEW_DOCUMENT_SEND_API1:Pseudo code


Sending  email in SAP is simple when we use the function module 'SO_NEW_DOCUMENT_SEND_API1'. The documentation of the function module is also provided in SAP. We are not going to explain each and every parameter of the function module. However, we will be a providing a simple pseudo code, that should help you in generating a new email.

Pseudo code is as below:
DATA: IT_MAILSUBJECT     TYPE SODOCCHGI1.
DATA: IT_MAILRECIPIENTS  TYPE STANDARD TABLE OF SOMLREC90 WITH HEADER LINE.
DATA: IT_MAILTXT         TYPE STANDARD TABLE OF SOLI      WITH HEADER LINE.
DATA: W_STRING(220) TYPE C.

*EMAIL LOGIC
* Construct Recipients
iT_MAILRECIPIENTS-REC_TYPE  'U'.
iT_MAILRECIPIENTS-RECEIVER = ‘asokav@rediffmail.com’.
APPEND iT_MAILRECIPIENTS .
CLEAR iT_MAILRECIPIENTS .

* Subject Construction.
iT_MAILSUBJECT-OBJ_NAME 'Test mail'.
IT_MAILSUBJECT-OBJ_LANGU SY-LANGU.
IT_MAILSUBJECT-OBJ_DESCR 'Test mail report.

*Email body
W_string = ‘Welcome to Learn Abap programming’.
it_mailtxt w_string.
APPEND it_mailtxt.
CLEAR it_mailtxt.
*Call function module
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
  EXPORTING
    DOCUMENT_DATA              IT_MAILSUBJECT
  TABLES
    OBJECT_CONTENT             IT_MAILTXT
    RECEIVERS                  IT_MAILRECIPIENTS
  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 EQ 0.
  COMMIT WORK.
*   Push mail out from SAP outbox
  SUBMIT RSCONN01 WITH MODE 'INT' AND RETURN.
ENDIF.

In some systems, we need to submit RSCONN01 is order to push the email.

This pseudo code is pretty simple to make one understand of how to use the function module. Go try using the same!

No comments:

Post a Comment