Many times I’ve had to develop a program for sending email, the code I’ve used is always the same except te part to get and fomat the informations to be sent, so I decided to develop a function, a little tool to be used and call as soon as I need to create a program for email.

My idea was to create a function module where all main activities were already managed and so I need only to take care to develop the code to get the informations.



the main parameters are:

SUBJECT: it’s email subject

MY_RECEIVERS: it’s a table filled with the receivers, it’s arranged on dictionary type table ZMAIL_RECEIVERS:


and the structure ZMAIL_RECEIVER is:


the field

– ZZGROUP          is to group several receivers together

– SMTP_ADDR     is email address

The rest of importing paramenters are optional because it depends on what it needs to insert in the mail:

TEXT               is the text for the body of email;

MY_SENDER    the current user is the sender by default, but it’s possible to set another use

I’ve tried to manage all main attachments I’m used to use:

TXT_ATTACH     is simple attachment for a text file, the parameter is a table in order to attach several files:



The fields

– OBJTP            is for the file type, usually TXT

– OBJDES         is for file name

– TEXT_DATA    is for the text

BIN_ATTACH     is simple attachment for a binary file, the parameter is a table in order to attach several files:



The fields

– OBJTP            is for the file type, for example PDF

– OBJDES         is for file name

– BIN_DATA      is for the data file

OTF_ATTACH is if it needs to attach a SAP print generated by sapscript or smartform, here it needs only to transfer the OTF data without any convertion



The fields

– OBJTP            is for the file type, usually PDF (actually the OTF data is always converted to ASCII or PDF file, the standard function CONVERT_OTF is used                           for convertion)

– OBJDES         is for file name

– OTF_DATA      is for the print data

SPOOL_ATTACH is if it needs to attach a SAP spool



The fields

– OBJDES       is for file name

– RQIDENT      is spool number

The function module RSPO_GET_ATTRIBUTES_SPOOLJOB is used to get the spool informations and the function modules CONVERT_OTFSPOOLJOB_2_PDF or CONVERT_ABAPSPOOLJOB_2_PDF (it depends on the kind of spool) convert the spool to PDF format.

ZIP_FILE_NAME is for the name of zip file, so all attachments can be zipped before being sent

The function module Z_SEND_MAIL uses the class CL_BCS to create and send the email and the class CL_ABAP_ZIP to generate the zip file, the result is exported into exporting parameters:


– RESULT will be equal to 0 if the email is sent successfully else will be equal to 1

– ERROR_MSG returns an eventual error message catched by exception class CX_BCS

This is very easy solution in order to create a little tool manages an email sending, I hope can be usefull to somebody and it can be used as model, I often read many topics about how to sent an email, here it can find all abap code it needs (or at least I hope so, just a little help)

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply