Online Tutorials & Training Materials | STechies.com
Register Login

Sample Report Program To Send E-mail From SAP To Specific Users Or To All Users Of A Client.

|| 0

Sample Report Program To Send E-mail From SAP To Specific Users Or To All Users Of A Client.
Stechies

 

REPORT YEMAIL.

 

TABLES: USR02.

DATA: C(15).

DATA: SENT LIKE SONV-FLAG.

DATA: EMAIL_ID LIKE SOFOLENTI1-OBJECT_ID.

DATA: BEGIN OF EMAIL_DATA.

        INCLUDE STRUCTURE SODOCCHGI1.

DATA: END OF EMAIL_DATA.

DATA: BEGIN OF EMAIL_SEND OCCURS 10.

        INCLUDE STRUCTURE SOMLRECI1.

DATA: END OF EMAIL_SEND.

DATA: BEGIN OF EMAIL_TEXT OCCURS 10.

        INCLUDE STRUCTURE SOLISTI1.

DATA: END OF EMAIL_TEXT.

****************************************************

PARAMETERS: ALL__CLI RADIOBUTTON GROUP RADI.

PARAMETERS: THIS_CLI RADIOBUTTON GROUP RADI.

PARAMETERS: SELECT__ RADIOBUTTON GROUP RADI.

SELECT-OPTIONS SEND_TO FOR C NO INTERVALS.

SELECTION-SCREEN SKIP.

 

PARAMETERS: SUBJECT(30).

SELECTION-SCREEN SKIP.

 

SELECTION-SCREEN COMMENT /1(20) TEXT-999.

SELECTION-SCREEN BEGIN OF LINE.

PARAMETERS: L1(84).

SELECTION-SCREEN END OF LINE.SELECTION-SCREEN BEGIN OF LINE.

PARAMETERS: L2(84).

SELECTION-SCREEN END OF LINE.SELECTION-SCREEN BEGIN OF LINE.

PARAMETERS: L3(84).

SELECTION-SCREEN END OF LINE.SELECTION-SCREEN BEGIN OF LINE.

PARAMETERS: L4(84).

SELECTION-SCREEN END OF LINE.SELECTION-SCREEN BEGIN OF LINE.

PARAMETERS: L5(84).

SELECTION-SCREEN END OF LINE.SELECTION-SCREEN BEGIN OF LINE.

PARAMETERS: L6(84).

SELECTION-SCREEN END OF LINE.SELECTION-SCREEN BEGIN OF LINE.

PARAMETERS: L7(84).

SELECTION-SCREEN END OF LINE.SELECTION-SCREEN BEGIN OF LINE.

PARAMETERS: L8(84).

SELECTION-SCREEN END OF LINE.SELECTION-SCREEN BEGIN OF LINE.

PARAMETERS: L9(84).

SELECTION-SCREEN END OF LINE.

***********************************************

EMAIL_TEXT-LINE = L1.

APPEND EMAIL_TEXT.

EMAIL_TEXT-LINE = L2.

APPEND EMAIL_TEXT.

EMAIL_TEXT-LINE = L3.

APPEND EMAIL_TEXT.

EMAIL_TEXT-LINE = L4.

APPEND EMAIL_TEXT.

EMAIL_TEXT-LINE = L5.

APPEND EMAIL_TEXT.

EMAIL_TEXT-LINE = L6.

APPEND EMAIL_TEXT.

EMAIL_TEXT-LINE = L7.

APPEND EMAIL_TEXT.

EMAIL_TEXT-LINE = L8.

APPEND EMAIL_TEXT.

EMAIL_TEXT-LINE = L9.

APPEND EMAIL_TEXT.

 

EMAIL_DATA-OBJ_NAME = 'MESSAGE'.

EMAIL_DATA-OBJ_DESCR = SUBJECT.

EMAIL_DATA-OBJ_LANGU = 'E'.

EMAIL_DATA-SENSITIVTY = 'P'.

EMAIL_DATA-OBJ_PRIO =  '1'.

EMAIL_DATA-NO_CHANGE = 'X'.

EMAIL_DATA-PRIORITY = '1'.

 

BREAK-POINT.

IF SELECT__ = 'X'.

  LOOP AT SEND_TO.

    EMAIL_SEND-RECEIVER = SEND_TO-LOW.

    EMAIL_SEND-REC_TYPE = 'U'.

    EMAIL_SEND-EXPRESS = 'X'.

    APPEND EMAIL_SEND.

  ENDLOOP.

ELSEIF THIS_CLI = 'X'.

  SELECT * FROM USR02.

    IF USR02-USTYP = 'A' AND USR02-BNAME NE 'SAP*'

    AND USR02-BNAME NE 'DDIC'.

      EMAIL_SEND-RECEIVER = USR02-BNAME.

      EMAIL_SEND-REC_TYPE = 'U'.

      EMAIL_SEND-EXPRESS = 'X'.

      APPEND EMAIL_SEND.

    ENDIF.

  ENDSELECT.

ELSEIF ALL__CLI = 'X'.

  SELECT * FROM USR02 CLIENT SPECIFIED.

    IF USR02-USTYP = 'A' AND USR02-BNAME NE 'SAP*'

    AND USR02-BNAME NE 'DDIC'.

      EMAIL_SEND-RECEIVER = USR02-BNAME.

      EMAIL_SEND-REC_TYPE = 'U'.

      EMAIL_SEND-EXPRESS = 'X'.

      APPEND EMAIL_SEND.

    ENDIF.

  ENDSELECT.

ENDIF.

BREAK-POINT.

EXIT.

*****************************************************

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

     EXPORTING

          DOCUMENT_DATA              = EMAIL_DATA

          DOCUMENT_TYPE              = 'RAW'

          PUT_IN_OUTBOX              = 'X'

     IMPORTING

          SENT_TO_ALL                = SENT

          NEW_OBJECT_ID              = EMAIL_ID

     TABLES

          OBJECT_CONTENT             = EMAIL_TEXT

          RECEIVERS                  = EMAIL_SEND

     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.

 

Thanks & Regards,