Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Office Integration for Word Template

Former Member
0 Kudos

Hello,

I got a problem that I want to fill (not create!) a word template with a custom report. This means I have a prepared Word template which already exists. I placed some fields there just like the address etc. that should be filled dynamically by SAP values. I was looking for SAP office integration that can maybe handle this, but I did not find any coding snippet that could help. All the snippets I found were for creating a new word file which I do not need. I "just" want to have 3 things.

(1) Use/ Upload a custom Word template with fields in it.

(2) Use this template in a custom report and fill the fields from the report.

(3) Save the filled template in SAP or workspace

Any hints for this?

Regards
Michael

8 REPLIES 8

ipravir
Active Contributor
0 Kudos

Hi Michael,

Through OLE programming you can display the information in MS Word.

Please find below link, where i have display the selected table information in MS Word with some customization like color etc.

Hope it can help you with your requirement.

Regards,

Praveer.

Former Member
0 Kudos

Hey Praveer,

thanks for the link but I know this one. It is completely filled with SAP values from a table.

I do not need something like this, I need a method or function which allows me to transfer in a word template prepared fields from SAP to MS word.

Regards
Michael

ipravir
Active Contributor

HI Michael,

As per you requirement, you have to update the already defined fields from WORD file.

for this, you can refer below program.

Program Name:  SAPRDEMO_FORM_INTERFACE.

Here, some already define value or fields are exist in WORD file. and by the selection of respective event, the entered or selected value from SAP screen, will transfer to respective fields of WORD file.

Select Run application in place to open WORD file in SAP screen.

Regards,

Praveer.

Former Member
0 Kudos

Yes I know that too and tried to work with it. It looks similar to my request. But I tried to copy it into my custom report and was not able to replace it. There are many factors in this report which I do not need. I just need the coding snippet which opens the word file and replaces the fields, but I was not able to find them in the report.

Regards
Michael

ipravir
Active Contributor
0 Kudos

Hi Michael,

Open the WORD file in SAP screen is in MODULE CREATE_BASIC_OBJECTS OUTPUT of the program, only you have to pass inplace eq 'X'.

and to set the data to respective information in WORD file you can follow the MODULE USER_COMMAND_0100 INPUT.

inside this module, a method has been called to set the data.

CALL METHOD HANDLE->SET_DATA

            EXPORTING FIELDS = TABEL2

                      CLEAR = 'X'.

I would suggest, don't copy the whole program, debug as per your requirement and create another program.

Regards,

Praveer.

Former Member
0 Kudos

And where can I put or read the word file?
I have a docx file on my computer which should be used for this.

former_member210008
Active Participant
0 Kudos

Did you try ZWWW? It's not standard but very good module to create reports in word and excel.

Juwin
Active Contributor
0 Kudos

Similar to XLSX, DOCX is an open source Microsoft Word document. Which means that, you will be able to use XML, to play around with the DOCX document.

http://blogs.msdn.com/b/chrisrae/archive/2010/09/25/where-is-the-documentation-for-office-2010-s-doc...

I would suggest you to do the following steps.

  1. Create a simple Word document and type in some words.
  2. From MS Word, save the document as a docx file.
  3. Change the extension of the document to .zip
  4. Unzip the file
  5. Look at the XML files created within the unzipped folder and locate the file /word/document.xml within the folder.
  6. Use notepad edit the words you had typed in earlier, in XML file
  7. Zip it back
  8. Then change the extension of the zip file to docx
  9. Now open the file with MS Word and you should see the changes in the document.

This should give you an idea on how to create your document template. You may load that document to mime repository and retrieve that in your program. You can use CL_ABAP_ZIP to perform zip/unzip within SAP. You can use XML classes in SAP to edit the XML values.

Thanks,

Juwin