Sending email with multiple tabs of excel as a single attachment in ABAP

By KIRUTHIKA P, L & T Infotech

Introduction

This article is to send email with cell formatted excel attachment having multiple worksheets. This objective can be achieved by OLE logic with creation of multiple sheets. This cannot be done by existing standard function modules. This can be created as Function module and we can use this function module wherever this requirement is needed by changing the import parameters. In this way, it is possible to improve the performance of the application by providing clarity of data in multiple tabs of excel sheet.

Objective

To send multiple tabs of excel sheet as a single attachment by email.

Steps

In this application, First create a Function Module with Receiver mail id as Import parameter.

Part 1

1.     Create one Function Module

Go to SE37 -> Give name of the Function Module -> Create  

Give Function group name ->Description -> Save

2.     Then create I_MAIL_ID of type ADR6-SMTP_ADDR as Import parameter , E_RETURN of type BAPIRET2 as Export parameter and T_TAB1 and T_TAB2 as tables parameter

3.     Save object either in Package or in local object

4.     Write logic in source code,

a)     Use XML code  and OLE logic

b)    Create First Workbook

c)     Then Create Styles for header, cell, Data

d)    Then Create 1st worksheet and Pass data to 1st worksheet with styles as per requirements.

e)     Then Create 2nd worksheet and pass another set of data to 2d worksheet as per specifications.

f)     Attachment Data will be in I_XML_DATA , loop this I_XML_DATA and append this to OBJBIN.

g)    Then Call Mail sending Function Module 'SO_NEW_DOCUMENT_ATT_SEND_API1' and pass this attachment data OBJBIN to CONTENTS_HEX.

h)     Pass Importing Parameter to Receiver Mail id of Function Module

i)      Thus FM will send mail with multiple tabs of excel sheet as an attachment through email.  

Sample Code

Click here to download the code

Output

Execute FM by providing values for sender id and tables and see the attachment with multiple tabs of excel sheet as Output. Here we are creating two worksheets in OLE logic, thus two tabs will be in output attachment excel sheet with cell formatting (Color, font, borders, etc ).  

 

 

 Summary  

This article is to send email with cell formatted excel attachment having multiple worksheets. This objective can be achieved by OLE logic with creation of multiple sheets. This cannot be done by existing standard function modules. This can be created as Function module and we can use this function module wherever this requirement is needed by changing the import parameters. In this way, it is possible to improve the performance of the application by providing clarity of data in multiple tabs of excel sheet.

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image