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: 

Mail Merge

Former Member
0 Kudos

Hi Experts,

I want to send the output to Word document instead of Smartforms/SAP Script I'm using Mail Merge OLE methods...I have created Template.doc(Mail Merge) and uploaded using class : WORD and type OT. I have used same class and methods of program : SAPRDEMO_MAILMERGE_INTERFACE. I have problem in populating the Mail Merge field values..Any one worked on SAP Mail Merge. Please help me in resolving this issue ?

Thanks,

Kumar

1 ACCEPTED SOLUTION

JL23
Active Contributor
7 REPLIES 7

JL23
Active Contributor

Former Member
0 Kudos

I have issue with method : get_fields it is returning 1 field name ITEM_NAME = " (not field name). I think i'm missing some setting in word. Please suggest me i'm using office - 2007 and ecc 6.0...

Thanks,

Kumar

JL23
Active Contributor
0 Kudos

have you seen this wiki, maybe it can help you further

http://wiki.sdn.sap.com/wiki/display/Snippets/PERFORMMAILMERGEDATATOMSWORD

Former Member
0 Kudos

Already I used wiki solution also...Not working.

-Kumar

Former Member
0 Kudos

Hi Kumar,

Mail merge functionality of Word called from SAP has certain restrictions when the word document is placed in SAP Container(In place).if this is the case you can only merge data into Merge fields and other mail merge rules such as IF,ASK etc will not function if the mail merge is done from SAP using I_OI_MAIL_MERGE interface. please refer SAP note 495627 which explains the differences between inplace/outplace display.

If you are opening word document outside(inplace = ' '),then the mail merge will be proper.

Normally to perform mail merge you should have a datasource(this should contain mail merge fields and their values) which will be used as reference to merge data into mail merge fields.

For performing Mail merge through SAP's I_OI_MAIL_MERGE interface, you have to obtain the mail merge interface instance from the I_OI_DOCUMENT_PROXY interface and then using this Mail merge instance set a data source using SET_DATA_SOURCE method, merge the records set in the data source using MERGE_ONE or MERGE_RANGE methods. After the data source is prepared and merge records are passed, to view the mail merge in word document, call VIEW method. Following this procedure should display data in merge fields.

I had a similar requirement with IF mail merge rules and also have some issues with mail merge functionality of Word document opened in SAP container.

0 Kudos

It is problem with word..I resolved it..Thank you for replying..

Former Member
0 Kudos

Hi,

Here I want to explain problem with merge fields in word for getting list of merge fields used in given document using method I_OI_MAIL_MERGE-get_fields

Merge fields Tags (with Problem)

Merge fields Tags(correct)

{MERGEFIELD "TAG1"}

{MERGEFIELD TAG1}

{MERGEFIELD TAG_H1}

{MERGEFIELD TAGH1}

*******

     CLEAR RETCODE. CLEAR ERROR.

     CALL METHOD MM_INTERFACE->GET_FIELDS

       EXPORTING

         NO_FLUSH   = ' '

       IMPORTING

         DESCR_LIST = LIST

         ERROR      = ERROR

         RETCODE    = RETCODE.


   LOOP AT TDD03L.

     LOOP AT LIST INTO WLIST WHERE ITEM_NAME = TDD03L-FIELDNAME.

       WFIELD-TABNAME = TDD03L-TABNAME.

       WFIELD-FIELDNAME = TDD03L-FIELDNAME.

       WFIELD-POSITION = TDD03L-POSITION.

       WFIELD-INTLENGTH = TDD03L-LENG.

       WFIELD-EXID = TDD03L-INTTYPE.

       WFIELD-OFFSET = T_OFFSET.

       APPEND WFIELD TO TFIELD.

     ENDLOOP.

     T_OFFSET = T_OFFSET + TDD03L-LENG.

   ENDLOOP.


*****

   CLEAR ERROR.

   CALL METHOD MM_INTERFACE->SET_DATA_SOURCE

**    EXPORTING

**      DDIC_NAME    = 'ZXXX'

****     no_flush     = 'X'

     IMPORTING

       RETCODE      = RETCODE

       ERROR        = ERROR

     CHANGING

       DATA_TABLE   = TDATA

       FIELDS_TABLE = TFIELD.


   IF RETCODE EQ C_OI_ERRORS=>RET_OK.

     " Document opened successfully

   ELSE.

     CALL METHOD C_OI_ERRORS=>RAISE_MESSAGE

       EXPORTING TYPE = 'I'.

   ENDIF.