Professional Documents
Culture Documents
ABAPLOVERS.BLOGSPOT.COM
ABAP OLE AUTOMATION
Check Video
http://www.rapidshare.com/
http://www.esnips.com/
http://www.slideshare.net/
http://www.megaupload.com
Subscribe
Delivered By FeedBurner
LOGON TO ABAPLOVERS.BLOGSPOT.COM
Follow Me on Twitter
ABAPLOVERS.BLOGSPOT.COM
ABAP OLE AUTOMATION
Z
Transactions
OLE
SOLE
LOGON TO ABAPLOVERS.BLOGSPOT.COM
Check Video
Follow Me on Twitter
ABAPLOVERS.BLOGSPOT.COM
ABAP OLE AUTOMATION
Check Video
In the above transaction you can start and stop each application to check if it has been
registered.
Run transaction SOLE to get a list of all the OLE applications registered in your
system. You can maintain these applications here.
LOGON TO ABAPLOVERS.BLOGSPOT.COM
Follow Me on Twitter
ABAPLOVERS.BLOGSPOT.COM
ABAP OLE AUTOMATION
Check Video
TOLE
OLE Applications
OLELOAD
SWOTOLE
SWOTTOLE
TOLET
CREATE OBJECT
SET PROPERTY
GET PROPERTY
CALL METHOD
FREE OBJECT
LOGON TO ABAPLOVERS.BLOGSPOT.COM
Follow Me on Twitter
ABAPLOVERS.BLOGSPOT.COM
ABAP OLE AUTOMATION
Check Video
The Desktop application serves as the OLE server to the calling ABAP program. For
example when the ABAP program makes calls to the OLE application the SAPGUI
servers as the client.
The create statement generates the object of this class. The following return code
values can be encountered.
SY-SUBRC = 0:
Object successfully generated.
SY-SUBRC = 1:
SAPGUI communication error.
SY-SUBRC = 2:
SAPGUI function call error. The frontend ports of SAPs OLE implementation modules
are implemented only under Windows and Apple Macintosh.
SY-SUBRC = 3:
The OLE-API call resulted in an error - possibly a storage space problem.
SY-SUBRC = 4:
The object is not registered with SAP.
Note that for each OLE object there has to be a variable holding handle data for that
LOGON TO ABAPLOVERS.BLOGSPOT.COM
Follow Me on Twitter
ABAPLOVERS.BLOGSPOT.COM
ABAP OLE AUTOMATION
Check Video
object. The type-pool ole2 defines the handle variable data of the type ole2_object.
For all the OLE automation programs OLE2INCL include should be used.
Please find below some examples of setting the properties of fonts, cell borders and
colors.
Font Properties.
SET PROPERTY OF name_font 'Name' = 'Times New Roman' .
SET PROPERTY OF size_font 'Size' = '12' .
SET PROPERTY OF bold_font 'Bold' = '0' . "Not bold
SET PROPERTY OF Italic_font 'Italic' = '0' . "Not Italic
SET PROPERTY OF underline_font 'Underline' = '0' . "Not underlined
Paragraph Formatting
SET PROPERTY OF allignment_parformat 'Alignment' = '3' . "Justified
LOGON TO ABAPLOVERS.BLOGSPOT.COM
Follow Me on Twitter
ABAPLOVERS.BLOGSPOT.COM
ABAP OLE AUTOMATION
Check Video
DATA: d_excel
d_cell1
d_cell2
d_cells
d_range
d_font
d_interior
d_columns
d_charts
d_chart
d_charttitle
d_charttitlech
d_chartob
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
ole2_object ,
ole2_object ,
ole2_object ,
ole2_object ,
ole2_object ,
ole2_object ,
ole2_object ,
ole2_object ,
ole2_object ,
ole2_object ,
ole2_object ,
ole2_object ,
ole2_object .
Sample code
CREATE OBJECT d_excel 'EXCEL.APPLICATION' .
SET PROPERTY OF d_excel 'Visible' = 1 .
GET PROPERTY OF d_excel 'Workbooks' = gs_wbooklist .
Formatting the Excel Cells
GET PROPERTY OF d_cell1 'Font' = d_font .
SET PROPERTY OF d_font 'Underline' = 2 .
SET PROPERTY OF d_font 'Bold' = 1 .
SET PROPERTY OF d_cell1 'HorizontalAlignment' = -4108 .
GET PROPERTY OF d_cell1 'Interior' = d_interior .
SET PROPERTY OF d_interior 'ColorIndex' = 15 . >>>>>>>>>> Check in the diagram given below
SET PROPERTY OF d_interior 'Pattern' = -4124 .
SET PROPERTY OF d_interior 'PatternColorIndex' = -4105 .
LOGON TO ABAPLOVERS.BLOGSPOT.COM
Follow Me on Twitter
ABAPLOVERS.BLOGSPOT.COM
ABAP OLE AUTOMATION
Check Video
Color code for ABAP is shown below, please use the numeric value as given in the figure below. For example if
you want the interior color of the Excel cell to be of the color Cyan then use the code 8.
LOGON TO ABAPLOVERS.BLOGSPOT.COM
Follow Me on Twitter
ABAPLOVERS.BLOGSPOT.COM
ABAP OLE AUTOMATION
Check Video
Color code for ABAP is shown below, please use the numeric value as given in the figure below.
LOGON TO ABAPLOVERS.BLOGSPOT.COM
Follow Me on Twitter
ABAPLOVERS.BLOGSPOT.COM
ABAP OLE AUTOMATION
Z
Sample Code
The following program transfers values from SAP to EXCEL with formating.
REPORT ZEXOLE2.
parameters: p_file like RLGRAP-FILENAME
default 'C:\exceldata\Customerdata.xls'.
data: d_file like p_file,
d_exsheet(10) value 'Customers',c_row type i,
d_scnt type i,
d_val(20),
d_wb(2).
parameters: p_exvis as checkbox default 'X',
p_workbk(2) type p default '01',
p_wsheet(2) type p default '01'.
CONSTANTS: OK TYPE I
INCLUDE OLE2INCL.
DATA: EXCEL
TYPE
WORKBOOK TYPE
SHEET
TYPE
CELL
TYPE
CELL1
TYPE
COLUMN
TYPE
RANGE
TYPE
BORDERS
TYPE
BUTTON
TYPE
INT
TYPE
FONT
TYPE
ROW
TYPE
VALUE 0.
OLE2_OBJECT,
OLE2_OBJECT,
OLE2_OBJECT,
OLE2_OBJECT,
OLE2_OBJECT,
OLE2_OBJECT,
OLE2_OBJECT,
OLE2_OBJECT,
OLE2_OBJECT,
OLE2_OBJECT,
OLE2_OBJECT,
OLE2_OBJECT.
LOGON TO ABAPLOVERS.BLOGSPOT.COM
Check Video
Follow Me on Twitter
ABAPLOVERS.BLOGSPOT.COM
ABAP OLE AUTOMATION
Z
books
ole_book
type ole2_object,
TYPE ole2_object.
do p_workbk times.
move p_file to d_file.
unpack sy-index to d_wb.
replace 'NN' with d_wb into d_file.
*
perform create_EXCEL.
* create sheets and save
perform sheet.
perform save_book.
enddo.
write: ' Done'.
*---------------------------------------------------------------------*
*
FORM create_excel
*
*---------------------------------------------------------------------*
*
........
*
*---------------------------------------------------------------------*
form create_excel.
CREATE OBJECT EXCEL 'EXCEL.APPLICATION'.
if sy-subrc ne 0.
write: / 'No EXCEL creation possible'.
stop.
endif.
set property of EXCEL 'DisplayAlerts' = 0.
*
LOGON TO ABAPLOVERS.BLOGSPOT.COM
Check Video
Follow Me on Twitter
ABAPLOVERS.BLOGSPOT.COM
ABAP OLE AUTOMATION
Z
if p_exvis eq 'X'.
SET PROPERTY OF EXCEL 'VISIBLE' = 1.
else.
SET PROPERTY OF EXCEL 'VISIBLE' = 0.
endif.
*
Create worksheet
set property of excel 'SheetsInNewWorkbook' = 1.
call method of workbook
'ADD'.
endform.
*---------------------------------------------------------------------*
*
FORM save_book
*
*---------------------------------------------------------------------*
*
........
*
*---------------------------------------------------------------------*
form save_book.
get property of excel 'ActiveSheet' = sheet.
free object sheet.
free object workbook.
GET PROPERTY OF EXCEL 'ActiveWorkbook' = WORKBOOK.
call method of workbook 'SAVEAS' exporting #1 = p_file #2 = 1.
call method of workbook 'CLOSE'.
call method of excel 'QUIT'.
free object sheet.
free object workbook.
free object excel.
endform.
*---------------------------------------------------------------------*
*
FORM sheet
*
*---------------------------------------------------------------------*
*
........
*
*---------------------------------------------------------------------*
LOGON TO ABAPLOVERS.BLOGSPOT.COM
Check Video
Follow Me on Twitter
ABAPLOVERS.BLOGSPOT.COM
ABAP OLE AUTOMATION
Z
form sheet.
do p_wsheet times.
unpack sy-index to d_exsheet+5(2).
if sy-index gt 1.
CALL METHOD OF EXCEL 'WORKSHEETS' = sheet.
call method of sheet 'ADD'.
free object sheet.
endif.
d_scnt = sy-index.
call method of excel
'WORKSHEETS' = SHEET EXPORTING #1 = d_scnt
call method of sheet
SET PROPERTY OF SHEET
free object sheet.
"OK
'ACTIVATE'.
'NAME'
= d_exsheet.
perform fill_sheet.
*
*
free
free
free
free
free
free
free
free
enddo.
free
free
free
free
object button.
object font.
object int.
object cell.
object: cell1.
object range.
object borders.
object: column, row.
object
object
object
object
font.
int.
cell.
cell1.
LOGON TO ABAPLOVERS.BLOGSPOT.COM
Check Video
Follow Me on Twitter
ABAPLOVERS.BLOGSPOT.COM
ABAP OLE AUTOMATION
Z
free object
free object
free object
free object
free object
endform.
range.
borders.
column.
row.
sheet.
*---------------------------------------------------------------------*
*
FORM border
*
*---------------------------------------------------------------------*
*
........
*
*---------------------------------------------------------------------*
* --> we
*
*---------------------------------------------------------------------*
form border using we.
*left
call method of CELL 'BORDERS' = BORDERS exporting #1 = '1'.
set property of borders 'LineStyle' = '1'.
set property of borders 'WEIGHT' = we.
"4=max
free object borders.
* right
call method of CELL 'BORDERS' = BORDERS exporting #1 = '2'.
set property of borders 'LineStyle' = '2'.
set property of borders 'WEIGHT' = we.
free object borders.
* top
call method of CELL 'BORDERS' = BORDERS exporting #1 = '3'.
set property of borders 'LineStyle' = '3'.
set property of borders 'WEIGHT' = we.
free object borders.
* bottom
call method of CELL 'BORDERS' = BORDERS exporting #1 = '4'.
set property of borders 'LineStyle' = '4'.
set property of borders 'WEIGHT' = we.
*
set property of borders 'ColorIndex' = 'xlAutomatic'.
free object borders.
endform.
LOGON TO ABAPLOVERS.BLOGSPOT.COM
Check Video
Follow Me on Twitter
ABAPLOVERS.BLOGSPOT.COM
ABAP OLE AUTOMATION
Z
*---------------------------------------------------------------------*
*
FORM border2
*
*---------------------------------------------------------------------*
*
........
*
*---------------------------------------------------------------------*
* --> we
*
*---------------------------------------------------------------------*
form border2 using we.
*left
call method of CELL 'BORDERS' = BORDERS exporting #1 = '1'.
set property of borders 'LineStyle' = '5'.
set property of borders 'WEIGHT' = we.
"4=max
free object borders.
* right
call method of CELL 'BORDERS' = BORDERS exporting #1 = '2'.
set property of borders 'LineStyle' = '6'.
set property of borders 'WEIGHT' = we.
free object borders.
* top
call method of CELL 'BORDERS' = BORDERS exporting #1 = '3'.
set property of borders 'LineStyle' = '7'.
set property of borders 'WEIGHT' = we.
free object borders.
* bottom
call method of CELL 'BORDERS' = BORDERS exporting #1 = '4'.
set property of borders 'LineStyle' = '8'.
set property of borders 'WEIGHT' = we.
*
set property of borders 'ColorIndex' = 'xlAutomatic'.
free object borders.
endform.
*---------------------------------------------------------------------*
*
FORM border3
*
*---------------------------------------------------------------------*
*
........
*
*---------------------------------------------------------------------*
* --> we
*
*---------------------------------------------------------------------*
form border3 using we.
LOGON TO ABAPLOVERS.BLOGSPOT.COM
Check Video
Follow Me on Twitter
ABAPLOVERS.BLOGSPOT.COM
ABAP OLE AUTOMATION
Z
*left
call method of CELL 'BORDERS' = BORDERS exporting #1 = '1'.
set property of borders 'LineStyle' = '10'.
set property of borders 'WEIGHT' = we.
"4=max
free object borders.
* right
call method of CELL 'BORDERS' = BORDERS exporting #1 = '2'.
set property of borders 'LineStyle' = '10'.
set property of borders 'WEIGHT' = we.
free object borders.
* top
call method of CELL 'BORDERS' = BORDERS exporting #1 = '3'.
set property of borders 'LineStyle' = '11'.
set property of borders 'WEIGHT' = we.
free object borders.
* bottom
call method of CELL 'BORDERS' = BORDERS exporting #1 = '4'.
set property of borders 'LineStyle' = '12'.
set property of borders 'WEIGHT' = we.
*
set property of borders 'ColorIndex' = 'xlAutomatic'.
free object borders.
endform.
*---------------------------------------------------------------------*
*
FORM fill_cell
*
*---------------------------------------------------------------------*
*
........
*
*---------------------------------------------------------------------*
* --> color
*
* --> pattern
*
*---------------------------------------------------------------------*
form fill_cell using color pattern.
call method of cell 'INTERIOR' = int.
set property of int 'ColorIndex' = color.
set property of int 'Pattern' = pattern.
free object int.
endform.
LOGON TO ABAPLOVERS.BLOGSPOT.COM
Check Video
Follow Me on Twitter
ABAPLOVERS.BLOGSPOT.COM
ABAP OLE AUTOMATION
Z
*---------------------------------------------------------------------*
*
FORM font
*
*---------------------------------------------------------------------*
*
........
*
*---------------------------------------------------------------------*
* --> bold
*
* --> size
*
*---------------------------------------------------------------------*
form font using bold size.
call method of CELL 'FONT' = font.
set property of font 'BOLD' = bold.
set property of font 'SIZE' = size.
free object font.
endform.
*---------------------------------------------------------------------*
*
FORM fill_sheet
*
*---------------------------------------------------------------------*
*
........
*
*---------------------------------------------------------------------*
form fill_sheet.
CALL METHOD OF EXCEL
'RANGE' = CELL EXPORTING #1 = 'A1'.
perform font
using 1 '10'.
SET PROPERTY OF CELL
'VALUE' = 'Counter'.
perform fill_cell
using '20' '1'.
perform border
using '2'.
free object cell.
d_val = 'Workbook-Count'.
move d_wb to d_val+16.
CALL METHOD OF EXCEL
'RANGE' = CELL EXPORTING #1 = 'B1'.
SET PROPERTY OF CELL
'VALUE' = d_val.
perform fill_cell using '14' '1'.
perform border using '4'.
free object cell.
d_val = 'Sheet-Count'.
unpack sy-index to d_val+12.
LOGON TO ABAPLOVERS.BLOGSPOT.COM
Check Video
Follow Me on Twitter
ABAPLOVERS.BLOGSPOT.COM
ABAP OLE AUTOMATION
Z
LOGON TO ABAPLOVERS.BLOGSPOT.COM
Check Video
Follow Me on Twitter
ABAPLOVERS.BLOGSPOT.COM
ABAP OLE AUTOMATION
Z
endform.
LOGON TO ABAPLOVERS.BLOGSPOT.COM
Check Video
Follow Me on Twitter
ABAPLOVERS.BLOGSPOT.COM
ABAP OLE AUTOMATION
Z
LOGON TO ABAPLOVERS.BLOGSPOT.COM
Check Video
Follow Me on Twitter
ABAPLOVERS.BLOGSPOT.COM
ABAP OLE AUTOMATION
Check Video
LOGON TO ABAPLOVERS.BLOGSPOT.COM