SAP Development Community of Experts
The Development Soap Box
Online ABAP Report
Excel with multiple Tabs
Canada Delivery Centre
SAP Development Community of Experts
Online ABAP Report Excel with multiple Tabs The Development Soap Box
Highlights:
Online ABAP Report
Initiate MS Excel on local machine
Display data on multiple tabs in Excel
Include a common report header on all tabs
Give each Tab a unique, meaningful name
Open and work with existing Excel files
SAP Development Community of Experts
Online ABAP Report Excel with multiple Tabs The Development Soap Box
ABAP Data
Workstation
Extractor
Instantiate
Excel Excel
Fix Format Data
Report OLE Object Workbook
Template
Report
Program
Data
Format
SAP Development Community of Experts
Online ABAP Report Excel with multiple Tabs The Development Soap Box
Implementation Approach:
Procedural
Object Oriented
SAP Development Community of Experts
Procedural Implementation The Development Soap Box
Custom Structure and Table Type to pass data to the FM
Tab
Row ID
Column ID
Value
Custom function module to display report
Uses OLE Object
Independent of the logic to collect report data
NOTES
Useful only for online reporting
Data needs to be sorted by Tab, RowID, ColumnID
SAP Development Community of Experts
Procedural Implementation Data Dictionary The Development Soap Box
Custom Structure and Table Type to pass data to the
FM
SAP Development Community of Experts
Procedural Implementation Function Group The Development Soap Box
Custom function module
SAP Development Community of Experts
Procedural Implementation Function Module -1 The Development Soap Box
Custom function module
i_data report data to be displayed
i_title report title
i_columns max number of columns in the report (used
to format the output)
Create each row to be displayed tab delimited string
Types:t_output(1500) typec,
tt_output typestandardtableoft_outputinitialsize0.
Data: lwa_output typet_output.
concatenatelwa_output
lwa_data-value
intolwa_output
separatedbycl_abap_char_utilities=>horizontal_tab.
SAP Development Community of Experts
Procedural Implementation Function Module -2 The Development Soap Box
Custom function module
Instantiating OLE Objects MS Excel Collections/Objects
data:excel_apptypeole2_object.
*startExcel
createobjectexcel_app'EXCEL.APPLICATION.
check_ole_errorsy-subrcole_error.
*addanewworkbook
callmethodofexcel_app'Workbooks'=workbooks.
callmethodofworkbooks'Add'=workbook.
* Add a new worksheet
getpropertyofworkbook'Worksheets'=worksheets.
callmethodofworksheets'Add'=activesheet.
* Set tab name for the current sheet
setpropertyofactivesheet'Name'=tab.
SAP Development Community of Experts
Procedural Implementation Function Module -3 The Development Soap Box
Custom function module
Transferring data over to Excel
* Export the data to clipboard
callmethodcl_gui_frontend_services=>clipboard_export
importing
data =it_output
changing
rc =l_rc
exceptions
cntl_error =1
error_no_gui =2
not_supported_by_gui =3
others =4.
* Select first cell and paste from clipboard
callmethodofexcel_app'Cells'=cells
exporting
#1=1
#2=1.
callmethodofcells'Select'.
callmethodofactivesheet'Paste'.
SAP Development Community of Experts
Procedural Implementation Code The Development Soap Box
Deployment
Create a custom Function Group and a function module - Z_OUTPUT_EXCEL_ONLINE
Text files for the code
- TOP Include TOP INCLUDE
- Form Include Form Include
- Function module - Z _EXCEL_OUTPUT_
ONLINE
SAP Development Community of Experts
Procedural Implementation Cons The Development Soap Box
Lacking:
Encapsulation
Code and data are contained to one instance
Inheritance
No cut and paste of common code.
Multiple instantiation
Several workbooks can be created and worked on simultaneously
SAP Development Community of Experts
Object Orientation Implementation The Development Soap Box
Custom Include Custom Class
CL_ONLNE_EXCEL
Independent of the logic to collect report data
No data dictionary objects required.
NOTES
Useful only for online reporting
Data can be provided in a predefined format the type is
declared in custom include or can be provided as a
standard table.
Data in predefined format needs to be sorted by Tab,
RowID, ColumnID
SAP Development Community of Experts
Custom Class Declaration The Development Soap Box
Using the custom class:
Data Declaration:
DATA: it_excel TYPEcl_online_excel_types=>tt_output,
it_title TYPEcl_online_excel_types=>tt_output,
lwa_excel TYPEcl_online_excel_types=>t_output,
l_rc TYPEsy-subrc.
DATA: l_online_excelTYPEREFTOcl_online_excel.
SAP Development Community of Experts
Custom Class Methods The Development Soap Box
Using the class methods:
CREATEOBJECTl_online_excel.
l_online_excel->add_title(
EXPORTING _tab_data =it_title
_rows=4
_columns =17).
l_online_excel->add_tabs(it_excel).
l_rc=l_online_excel->add_tabs_general(_tab_data =it_newtab
_tabname ='Customers'
_display ='X'
_title =space).
l_online_excel->start_excel(EXCEPTIONSole_error=1).
lwa_newtab='thisisnewtab'.
APPENDlwa_newtabTOit_newtab.
l_rc=l_online_excel->display_new_tab(
_clipboard =it_newtab
_tabname ='newtab').
SAP Development Community of Experts
Custom Class Methods Existing Files The Development Soap Box
Open Existing File:
l_online_excel->open_file(
exporting _filename =C:\Sheet1.xls'
exceptionsole_error =1).
OpenNewfilebasedonatemplate:
l_online_excel->start_excel(
exporting_template ='ZZTEST'
_filename =p_file
exceptionsole_error =1).
Add data to spreadsheets:
l_online_excel->add_data_to_tab(
exporting_tab_data =it_newtab
_tabname ='300'
changing_start_row =lv_start_row
_start_col =lv_start_col
_returncode =l_rc).
SAP Development Community of Experts
Custom Class Methods Format Options The Development Soap Box
lv_borderbottom-linestyle=cl_online_excel=>cxl_border_continuous.
lv_borderbottom-weight=cl_online_excel=>cxl_ln_weight_light.
l_rc=l_online_excel->set_format(_start_row =5
_start_col =7
_end_row =5
_end_col =7
_halignment =cxl_halign_centre
_fontstyle =cxl_font_bold
_borderleft =lv_borderleft
_borderright =lv_borderright
_bordertop =lv_bordertop
_borderbottom =lv_borderbottom).
.
SAP Development Community of Experts
Online ABAP Report Excel with multiple Tabs The Development Soap Box
Deployment
Create a custom include for the custom class - CL_ONLINE_EXCEL
Text file for the code
- Custom Include CL_ONLINE_EXCEL
SAP Development Community of Experts
Online ABAP Report Excel with multiple Tabs The Development Soap Box
Questions