Skip to Content
0
Mar 22, 2012 at 05:59 PM

How to load a MS Word document template into SAP database table?

405 Views

Dear experts,

I have come across a following piece of code. It appears that a MS Word document template was created and then loaded into SAP. It appears to me that following piece of code is trying to retrieve that template (using IMPORT statement) and then opening that 'MS word' document template. Can someone help me understand that how was the template loaded into SAP database in the beginning? And can I see that template without using the ABAP code? My requiremnt is that we need to replace original template with another template into SAP.

Thanks.

ABAPer.

*-------------------------------------------------------------------------

DATA: document TYPE REF TO i_oi_document_proxy.
DATA: BEGIN OF t_template OCCURS 0,
line(255),
END OF t_template.

srtfd = 'CONC WORD TEMPLATE'.

PERFORM set_shape_defaults.

IMPORT %tab TO t_template "Read template.
%l TO temp_size
FROM DATABASE indx(zz) ID srtfd.


CALL METHOD document->open_document_from_table
EXPORTING
document_table = t_template[]
document_size = temp_size
document_title = 'QNATT'
open_inplace = space
IMPORTING
retcode = retcode.

FORM set_shape_defaults.

DATA: h_word TYPE ole2_object,
h_docs TYPE ole2_object,
h_doc1 TYPE ole2_object,
h_shps TYPE ole2_object,
h_shap TYPE ole2_object,
h_wrap TYPE ole2_object.

CREATE OBJECT h_word 'Word.Application' .
SET PROPERTY OF h_word 'visible' = 0.

CALL METHOD OF h_word 'Documents' = h_docs.
CALL METHOD OF h_docs 'Add' = h_doc1.
GET PROPERTY OF h_doc1 'Shapes' = h_shps.
CALL METHOD OF h_shps 'AddShape' = h_shap
EXPORTING
#1 = 9
#2 = '265.05'
#3 = '117.2'
#4 = '72'
#5 = '72'.

GET PROPERTY OF h_shap 'WrapFormat' = h_wrap.
SET PROPERTY OF h_wrap 'Type' = 3.
CALL METHOD OF h_shap 'SetShapesDefaultProperties'.
CALL METHOD OF h_doc1 'Close'
EXPORTING
#1 = 0.
CALL METHOD OF h_word 'Quit'.

FREE OBJECT: h_word,
h_docs,
h_doc1,
h_shps,
h_shap,
h_wrap.