Skip to Content
0
Former Member
Nov 25, 2011 at 02:33 AM

ECC6Ehp5 abap call OLE have error

94 Views

Dear All,

Our system from ECC5 upgrade to ECC6 Ehp5,Now we have some abap program cann't used it,We checked it,They are all call OLE write data to word.The program source code:

program zchangeword.

INCLUDE ole2incl .

DATA gs_word TYPE ole2_object . "OLE object handle

DATA gs_documents TYPE ole2_object .

DATA gs_actdoc TYPE ole2_object .

DATA gs_application TYPE ole2_object .

DATA gs_selection TYPE ole2_object .

DATA gs_bookmark TYPE ole2_object.

DATA gs_count TYPE ole2_object.

DATA gs_actwindow TYPE ole2_object.

DATA gs_actpane TYPE ole2_object.

DATA gs_view TYPE ole2_object.

DATA gs_font TYPE ole2_object.

DATA docpath TYPE string.

DATA l_dokst TYPE tdws-dokst.

docpath = 'c:\temp\20111124121443_TCDEV0101.doc'.

CREATE OBJECT gs_word 'WORD.APPLICATION' .

IF sy-subrc NE 0 .

MESSAGE 'Error while creating OLE object!' TYPE 'I'.

LEAVE PROGRAM .

ENDIF .

SET PROPERTY OF gs_word 'Visible' = '1' .

GET PROPERTY OF gs_word 'Documents' = gs_documents .

CALL METHOD OF

gs_documents

'Open'

EXPORTING

#1 = docpath.

GET PROPERTY OF gs_word 'ActiveDocument' = gs_actdoc .

CALL METHOD OF

gs_actdoc

'Unprotect'.

GET PROPERTY OF gs_actdoc 'Bookmarks' = gs_bookmark.

GET PROPERTY OF gs_bookmark 'Count' = gs_count.

GET PROPERTY OF gs_actdoc 'Application' = gs_application .

GET PROPERTY OF gs_application 'Selection' = gs_selection .

PERFORM replace USING 'Y0_NAME' 'TEST'.

PERFORM replace USING 'Y0_DATE' '2011.11.24'.

***关闭WORD文件

CALL METHOD OF

gs_actdoc

'Close'

EXPORTING

#1 = '-1'.

CALL METHOD OF

gs_word

'Quit'.

FREE OBJECT: gs_word,gs_documents,gs_actdoc,gs_application,gs_selection.&----


*& Form replace

&----


* text

----


* -->P_FINDTEXT text

  • -->P_REPLACETEXT text

----


FORM replace USING p_findtext

p_replacetext.

CALL METHOD OF

gs_selection

'GoTo'

EXPORTING

#1 = '-1'

#2 = 0

#3 = 0

#4 = p_findtext.

CALL METHOD OF

gs_selection

'MoveEnd'

EXPORTING

#1 = '5'

#2 = '1'.

CALL METHOD OF

gs_selection

'Delete'.

  • CALL METHOD OF GS_FIND 'ClearFormatting'.

  • CALL METHOD OF GS_FIND 'Execute'.

CALL METHOD OF

gs_selection

'TypeText'

EXPORTING

#1 = p_replacetext.

ENDFORM. " REPLACE

The code line "GET PROPERTY OF gs_word 'Documents' = gs_documents ."

If the ERP system is ECC5.0,the variable gs_documents can return value,

But system is ECC6 Ehp5 the variable gs_documents cann't return value,Then the program cann't change the word file,Who can help me?