I was working in one Project and there came a requirement that if a customer process any output form , the output should be displayed as formatted excel and if given a print it should send the excel as email in background.

Now we had traditional ways of doing in SAP


  1. 1. 1. Without any formatting you could get all the data into an internal table and create an excel.This could be attained by use of this function module . The limitation here is we can’t format make any columns bold or can’t colour the data. If we want to just populate some data in rows and column and want to send it as an email ,we could achieve this easily.
  2. 2. 2. Second way of a formatted excel is using OLE method ( Object link Enable ) method in which we have all the functions to create a formatted excel with colors and bold orders. But the limitation here is we have to generate the output in foreground ( presentation server ) , it takes time as contents gets created at your presentation server. So the limitations are no background processing and performance issue as time take in dyamic content creation

Now I had a challenge that what could be the best way to generate a formatted excel and also process the output in background and send it as excel attachment to the desired recipients.

So I had digged out here and there and found that SAP has added the concept of ‘IXML’ in 2010 in their library functions and we could actually generate the formatted excel and also send as an email attachment. Infact SCN was very helpful I could find the generation of excel , however I din’t find a good source code which process the IXML data in background and send as an email attachment.

I hope it would be good for all those who are looking to implement such functionality .

Please let me know your feedback , suggestions and query further to this.

**** Decalaration Please go through the text file for decalartion part *******

*** When ever you write logic for an output form you have to define the entry node , when it is called from NACE.

Get all the data you require based on your functional requirements to process the data

** GT_FINAL is my internal table , where I had all the data which has to populated in my output. There are around 18 columns ( Fields ) in which data is being copied.

** Get file path is when you want the user an option to see the output/save the output in their desktop/presentation server you have to specify where you want to place the file in their system. So we use the below function module **

** Distributing the whole program in a modular way , calling the subroutines for specific functionality , as we do in conventional way.**


*&———————————————————————*
*& Form PROCESSING
*&———————————————————————*

FORM processing.
PERFORM get_data. “

*** PROCESS XML DATA IS THE MOST IMPORTANT SUB ROUTINE WHICH TELL US HOW WE CAN USE OUR INTERNAL TABLE DATA , FORMAT IT and GENERATE THE FORMATTED EXCEl ***


PERFORM process_xml_data. ” Create excel through  xml code for sending as an attachment
PERFORM get_file_path. ” Get the file path
PERFORM download_excel. “Download the processed excel in desktop

*** HOW TO PROCESS THE FORMATTED EXCEL IN BACKGROUND and SEND as an EXCEL ATTACHMENT ***


PERFORM send_mail1. “Sending the excel output via mail

ENDFORM. ” PROCESSING


*&———————————————————————*
*& Form PROCESS_XML_DATA
*&———————————————————————*
* Process the xml data to create an excel
*———————————————————————-*
FORM process_xml_data .

* Creating a ixml Factory
g_ixml
= cl_ixml=>create( ).

* Creating the DOM Object Model
g_document
= g_ixml->create_document( ).

*** Little help on the IXML Hierarchy ****

** Create a workbook **

**Set attributes for the workbook **

** Create Node for document **

** We need to attach a style to every node **

** Attributes of style would be setting up the alignment , font , bold , color etc ***

** Style Syntax : ID and give name , create different styles if properties are different for different rows **

** For every cell of excel you need to specify four borders , right , left , bottom and top **

** Create a table rows * Columns **

** Create Rows , attach the style to the row and define the properties **

** Similarly do for column **

** All syntax given in the document below **


* Create Root Node ‘Workbook’
g_element_root 
= g_document->create_simple_element( name = ‘Workbook’  parent = g_document ).
g_element_root
->set_attribute( name = ‘xmlns’  value = ‘urn:schemas-microsoft-com:office:spreadsheet’ ).

g_ns_attribute = g_document->create_namespace_decl( name = ‘ss’  prefix = ‘xmlns’  uri = ‘urn:schemas-microsoft-com:office:spreadsheet’ ).
g_element_root
->set_attribute_node( g_ns_attribute ).   

g_ns_attribute = g_document->create_namespace_decl( name = ‘x’  prefix = ‘xmlns’  uri = ‘urn:schemas-microsoft-com:office:excel’ ).
g_element_root
->set_attribute_node( g_ns_attribute ).   

* Create node for document properties.
r_element_properties
= g_document->create_simple_element( name = ‘TEST_REPORT’  parent = g_element_root ).
g_value
= syuname.
g_document
->create_simple_element( name = ‘Author’  value = g_value  parent = r_element_properties  ).

* Styles
r_styles
= g_document->create_simple_element( name = ‘Styles’  parent = g_element_root  ).

* Style for Header
r_style 
= g_document->create_simple_element( name = ‘Style’  parent = r_styles  ).
r_style
->set_attribute_ns( name = ‘ID’  prefix = ‘ss’  value = ‘Header’ ).

r_format  = g_document->create_simple_element( name = ‘Font’  parent = r_style  ).
r_format
->set_attribute_ns( name = ‘Bold’  prefix = ‘ss’  value = ‘1’ ).

r_format  = g_document->create_simple_element( name = ‘Interior’ parent = r_style  ).
r_format
->set_attribute_ns( name = ‘Color’  prefix = ‘ss’  value = ‘#FFFFFF’ ).
r_format
->set_attribute_ns( name = ‘Pattern’ prefix = ‘ss’  value = ‘Solid’ ).

r_format  = g_document->create_simple_element( name = ‘Alignment’  parent = r_style  ).
r_format
->set_attribute_ns( name = ‘Vertical’  prefix = ‘ss’  value = ‘Center’ ).
r_format
->set_attribute_ns( name = ‘WrapText’  prefix = ‘ss’  value = ‘1’ ).

r_border  = g_document->create_simple_element( name = ‘Borders’  parent = r_style ).
r_format 
= g_document->create_simple_element( name = ‘Border’  parent = r_border  ).
r_format
->set_attribute_ns( name = ‘Position’  prefix = ‘ss’  value = ‘Bottom’ ).
r_format
->set_attribute_ns( name = ‘LineStyle’  prefix = ‘ss’  value = ‘Continuous’ ).
r_format
->set_attribute_ns( name = ‘Weight’  prefix = ‘ss’  value = ‘1’ ).

r_format->set_attribute_ns( name = ‘Weight’  prefix = ‘ss’  value = ‘1’ ).

r_style  = g_document->create_simple_element( name = ‘Style’  parent = r_styles  ).
r_style
->set_attribute_ns( name = ‘ID’  prefix = ‘ss’  value = ‘Data’ ).

** Create a new style for Delivery Number
r_style5 
= g_document->create_simple_element( name = ‘Style’  parent = r_styles  ).
r_style5
->set_attribute_ns( name = ‘ID’  prefix = ‘ss’  value = ‘Data5’ ).

r_format  = g_document->create_simple_element( name = ‘Font’  parent = r_style5  ).
r_format
->set_attribute_ns( name = ‘Bold’  prefix = ‘ss’  value = ‘1’ ).

r_format  = g_document->create_simple_element( name = ‘Interior’ parent = r_style5  ).
r_format
->set_attribute_ns( name = ‘Color’  prefix = ‘ss’  value = ‘#1E90FF’ ).
r_format
->set_attribute_ns( name = ‘Pattern’ prefix = ‘ss’  value = ‘Solid’ ).

r_format  = g_document->create_simple_element( name = ‘Alignment’  parent = r_style5  ).
r_format
->set_attribute_ns( name = ‘Vertical’  prefix = ‘ss’  value = ‘Center’ ).
r_format
->set_attribute_ns( name = ‘WrapText’  prefix = ‘ss’  value = ‘1’ ).
r_border 
= g_document->create_simple_element( name = ‘Borders’  parent = r_style5 ).

*  * Border Bottom

r_format  = g_document->create_simple_element( name = ‘Border’  parent = r_border  ).
r_format
->set_attribute_ns( name = ‘Position’  prefix = ‘ss’  value = ‘Bottom’ ).
r_format
->set_attribute_ns( name = ‘LineStyle’  prefix = ‘ss’  value = ‘Continuous’ ).
r_format
->set_attribute_ns( name = ‘Weight’  prefix = ‘ss’  value = ‘1’ ).

**  Create Borders Bottom Left , top , right in the same way ***

r_format  = g_document->create_simple_element( name = ‘Border’  parent = r_border  ).
r_format
->set_attribute_ns( name = ‘Position’  prefix = ‘ss’  value = ‘Left’ ).
r_format
->set_attribute_ns( name = ‘LineStyle’  prefix = ‘ss’  value = ‘Continuous’ ).
r_format
->set_attribute_ns( name = ‘Weight’  prefix = ‘ss’  value = ‘1’ ).

* * Top
r_format 
= g_document->create_simple_element( name = ‘Border’  parent = r_border  ).
r_format
->set_attribute_ns( name = ‘Position’  prefix = ‘ss’  value = ‘Top’ ).
r_format
->set_attribute_ns( name = ‘LineStyle’  prefix = ‘ss’  value = ‘Continuous’ ).
r_format
->set_attribute_ns( name = ‘Weight’  prefix = ‘ss’  value = ‘1’).

** Ri