Sending SAPOffice mail
This ABAP program will allow you to send email from SAPOffice.
Sending SAPOffice mail
By Sudarshan Karkada
SAP supplies a function module 'SO_OBJECT_SEND' to allow you to send SAPOffice mails from within your ABAP programs. However, using that function module is complex and takes a lot of time to understand.
The following function module is just a wrap around for SO_OBJECT_SEND and takes much of the complexity out of the process. This function module not only sends a SAPOffice mail but also points to the current spool list. As you can see, many of the parameters have their defaults.
Parameter Descriptions
Either RECEPIENT or DLI must be specified. If the mail should be sent to several people, create a distribution list and supply its name for DLI.
Internal table TEXT should contain the body of the mail message.
While this function module can be used as it is, it is just an example. SO_OBJECT_SEND is very comprehensive and many of the features are omitted from this example. You are encouraged to examine SO_OBJECT_SEND, see all the available features, and change this function module to suit your requirements.
FUNCTION Z_SEND_MAIL_FOR_SPOOLLIST. *"---------------------------------------------------------------------- *"*"Local interface: *" IMPORTING *" VALUE(SPOOLNUMBER) LIKE SY-SPONO DEFAULT SY-SPONO *" VALUE(MAILNAME) LIKE SOOD1-OBJNAM DEFAULT 'NOTE' *" VALUE(SUBJECT) LIKE SOOD1-OBJDES *" VALUE(RECEPIENT) LIKE SY-UNAME OPTIONAL *" VALUE(DLI) LIKE SOOS1-DLINAM OPTIONAL *" TABLES *" TEXT STRUCTURE SOLI OPTIONAL *" EXCEPTIONS *" ERROR *"---------------------------------------------------------------------- DATA: OBJECT_HD_CHANGE LIKE SOOD1 OCCURS 0 WITH HEADER LINE, OBJPARA LIKE SELC OCCURS 0 WITH HEADER LINE, RECEIVERS LIKE SOOS1 OCCURS 0 WITH HEADER LINE. OBJECT_HD_CHANGE-OBJLA = SY-LANGU. OBJECT_HD_CHANGE-OBJNAM = MAILNAME. OBJECT_HD_CHANGE-OBJDES = SUBJECT. OBJECT_HD_CHANGE-OBJSNS = 'F'. OBJECT_HD_CHANGE-VMTYP = 'T'. OBJECT_HD_CHANGE-SKIPS = 'X'. OBJECT_HD_CHANGE-ACNAM = 'SP01'. OBJECT_HD_CHANGE-OBJCP = 'X'. RECEIVERS-RCDAT = SY-DATUM. RECEIVERS-RCTIM = SY-UZEIT. IF DLI IS INITIAL. RECEIVERS-RECNAM = RECEPIENT. RECEIVERS-RTUNAM = RECEPIENT. ELSE. RECEIVERS-RECNAM = DLI. RECEIVERS-ADR_NAME = DLI. RECEIVERS-RECESC = 'C'. ENDIF. RECEIVERS-SNDEX = 'X'. " Express-Mail APPEND RECEIVERS. OBJPARA-NAME = 'SPI'. OBJPARA-LOW = SPOOLNUMBER. APPEND OBJPARA. CALL FUNCTION 'SO_OBJECT_SEND' EXPORTING OBJECT_HD_CHANGE = OBJECT_HD_CHANGE OBJECT_TYPE = 'RAW' OWNER = SY-UNAME TABLES OBJCONT = TEXT OBJPARA = OBJPARA RECEIVERS = RECEIVERS EXCEPTIONS OTHERS = 01. IF SY-SUBRC NE 0. RAISE ERROR. ENDIF. ENDFUNCTION.
Visit Sudarshan Karkada's website for more great ABAP programs.
Did you like this tip? Send us an email to let us know what you think.