Está en la página 1de 4

1

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

*----------------------------------------------------------------------*
*
INCLUDE ZIOIEXCEL
*
*----------------------------------------------------------------------*
* Instantiates the control framework using i_oi_document factory.
* Excapsulates SAP Office Integration specific functionality. Uses the
* i_oi_document_proxy class to create the document link then
* uses the i_oi_table collection for transporting SAP internal tables
* from the server to the client for display in the active document
* server.
INCLUDE <CTLDEF>.
"General Definitions For Controls (CET)
* Platform- and application-indep. Office integration
INCLUDE OFFICEINTEGRATIONINCLUDE.
CLASS COIEXCEL DEFINITION.
PUBLIC SECTION.

"Excel DOI wrapper class

* Create the control framework and returns a document proxy interface


METHODS: CONSTRUCTOR,
* Clean up routine
DESTROY.
* Catch the on_close event to process cleanup
METHODS: ON_CLOSE_DOCUMENT
FOR EVENT ON_CLOSE_DOCUMENT OF I_OI_DOCUMENT_PROXY.
METHODS: CREATEDOCUMENT
"Not used
IMPORTING S_DOCTITLE TYPE C
EXPORTING RETCODE TYPE T_OI_RET_STRING.
METHODS: OPENDOCUMENT
IMPORTING FILEURL TYPE C
EXPORTING RETCODE TYPE T_OI_RET_STRING.
METHODS: TRANSFERTABLE
IMPORTING S_TABLENAME TYPE C
EXPORTING RETCODE TYPE T_OI_RET_STRING
CHANGING I_TAB TYPE TABLE.
METHODS: LAUNCHSE16 IMPORTING C_TBLNAME TYPE C
C_FILEPATH TYPE C
CHANGING TBL_TAB TYPE TABLE.
PRIVATE SECTION.
DATA:
H_FACTORY TYPE REF TO I_OI_DOCUMENT_FACTORY,
H_TABLES TYPE REF TO I_OI_TABLE_COLLECTION,
H_DOCUMENT TYPE REF TO I_OI_DOCUMENT_PROXY,
S_RETCODE TYPE T_OI_RET_STRING,
S_FILEURL(256) TYPE C,
S_DOCURL(256) TYPE C.
ENDCLASS.
CLASS COIEXCEL IMPLEMENTATION.
METHOD CONSTRUCTOR.
*----------------------------------------------------------------------* For external execution we simply use the factory class. (vs 4.5)
*
*----------------------------------------------------------------------DATA: DOCUMENT_EXCEL TYPE SOI_DOCUMENT_TYPE
VALUE SOI_DOCTYPE_EXCEL97_SHEET.

58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114

CALL FUNCTION 'CONTROL_INIT'


"Initialize the control framework
EXCEPTIONS
CONTROL_INIT_ERROR = 1
OTHERS
= 2.
Starting point - get a reference to the control framework
call method c_oi_factory_creator=>get_document_factory
exporting factory_type = 'OLE'
IMPORTING FACTORY = H_FACTORY
RETCODE = S_RETCODE.
call method c_oi_errors=>show_message exporting type = 'E'.
DOI Container object creation
CALL METHOD H_FACTORY->START_FACTORY
EXPORTING R3_APPLICATION_NAME = 'SAP-Excel DOI'
REGISTER_ON_CLOSE_EVENT = 'X'
IMPORTING RETCODE = S_RETCODE.
Get a reference to the document proxy
CALL METHOD H_FACTORY->GET_DOCUMENT_PROXY
EXPORTING DOCUMENT_TYPE = DOCUMENT_EXCEL
IMPORTING DOCUMENT_PROXY = H_DOCUMENT
RETCODE = S_RETCODE.
CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE
EXPORTING TYPE = 'E'.
Register the on_close event
SET HANDLER ME->ON_CLOSE_DOCUMENT FOR H_DOCUMENT.
ENDMETHOD.

" Constructor.. COIExcel

* Cleanup
METHOD DESTROY.
IF NOT H_TABLES IS INITIAL.
CALL METHOD H_TABLES->REMOVE_ALL_TABLES
IMPORTING RETCODE = S_RETCODE.
FREE H_TABLES.
ENDIF.
IF NOT H_FACTORY IS INITIAL.
CALL METHOD H_FACTORY->STOP_FACTORY.
FREE H_FACTORY.
ENDIF.
FREE H_DOCUMENT.
CALL FUNCTION 'CONTROL_EXIT'.
ENDMETHOD.
*

" Destructor.... COIExcel

METHOD ON_CLOSE_DOCUMENT.
for event on_close_document of i_oi_document_proxy.
IF NOT H_DOCUMENT IS INITIAL.
CALL METHOD H_DOCUMENT->CLOSE_DOCUMENT
IMPORTING RETCODE = S_RETCODE.
CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE
EXPORTING TYPE = 'E'.
ENDIF.

* Cleanup the DOI allocations and the control framework.


CALL METHOD ME->DESTROY.

115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171

*
*

message id 'mo' type 'S' number '001' with 'Enter selection table.'.
ENDMETHOD.
METHOD CREATEDOCUMENT.
importing s_doctitle type c
exporting s_retcode type t_oi_ret_string.
IF NOT H_DOCUMENT IS INITIAL.
CALL METHOD H_DOCUMENT->CREATE_DOCUMENT
EXPORTING OPEN_INPLACE = ' '
DOCUMENT_TITLE = S_DOCTITLE
IMPORTING RETCODE = S_RETCODE.
CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE EXPORTING TYPE = 'E'.
ENDIF.
ENDMETHOD.

* Parameters are set to open the document specified by fileurl,


* opened externally, and run the startup macro that resides
* inside the Excel document.
METHOD OPENDOCUMENT.
*
importing fileurl type c
*
exporting s_retcode type t_oi_ret_string.
CALL METHOD H_DOCUMENT->OPEN_DOCUMENT
EXPORTING
DOCUMENT_URL = FILEURL
OPEN_INPLACE = ' '
STARTUP_MACRO
= 'Module1.LoadR3Data'
IMPORTING RETCODE = S_RETCODE.
CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE EXPORTING TYPE ='E'.
ENDMETHOD.
*
*
*

METHOD TRANSFERTABLE.
importing s_tblname type c
exporting retcode type t_oi_ret_string
changing i_tab type table
IF H_TABLES IS INITIAL.
CALL METHOD H_FACTORY->GET_TABLE_COLLECTION
IMPORTING TABLE_COLLECTION = H_TABLES
RETCODE = S_RETCODE.
CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE EXPORTING TYPE = 'E'.
ENDIF.

*transfer data to presentation server


CALL METHOD H_TABLES->ADD_TABLE
EXPORTING TABLE_NAME
= 'ITAB'
TABLE_TYPE
= H_TABLES->TABLE_TYPE_OUTPUT
DDIC_NAME
= S_TABLENAME
DESCRIPTION = 'Block Data'
IMPORTING
RETCODE
= S_RETCODE
CHANGING DATA_TABLE
= I_TAB.
RETCODE = S_RETCODE.

172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190

ENDMETHOD.
* Specific method for use in the ZBTableListGeneration program.
* Simplifies the dynamic program creation
METHOD LAUNCHSE16.
*
importing c_tblname type c
*
c_filepath type c
*
changing tbl_tab type table
CALL METHOD ME->TRANSFERTABLE
EXPORTING S_TABLENAME = C_TBLNAME
IMPORTING RETCODE = S_RETCODE
CHANGING I_TAB = TBL_TAB.
CALL METHOD ME->OPENDOCUMENT
EXPORTING FILEURL = C_FILEPATH.
ENDMETHOD.
ENDCLASS.

"COIEXCEL Implemetation

También podría gustarte