Requirement 3 – How to Send Email with Excel as Attachment using ABAP.

Authored by

Requirement:  Send a excel sheet as E-mail attachment using CL_BCS for the displayed ALV.

To send a excel sheet as e-mail attachment,

    1. 1. Create a button in application toolbar to send a mail.
    2. 2. Handle event on click of button send email.
  1. 3. Display ALV using CL_SALV_TABLES.

Go to SE38,

Define a local class, here we make everything static CLASS-DATA for the sake of simplicity.

Add a button in application toolbar to send mail.

Go to SE80, Create GUI Status.

When GUI Status is created it is empty.

To add standard buttons and custom buttons, we copy a standard GUI Status to the GUI status which we created to our report.

How to copy standard GUI Status?

  • Go to SE38, enter SAPLSALV and click on Display Object List icon.

Copy the STANDARD GUI Status to our report program.

Now add a new button in the application toolbar and double click on it.

Enter Function Text,

Save and activate the changes.

 

Now navigate to SE38,

  • Define a method to fetch data from database.

Method GET_DATA

 Handle event on click of button to send a mail.

Method ON_USER_COMMAND     

  • Set screen status, register the event and display ALV.

Complete Code:

Result:

 

Note: If the mail isn’t received in the inbox, go to the transaction SOST to see whether the mails are triggered. If it is not triggered, check if the configurations are in place.