Office Integrator ILE RPG Sample for calling a Single Letter Mail Merge
From Support
The following code sample should be keyed into a source member named TSTMRG1R in source file SOURCE in library RJSOFFICE or in your own library. The source member source type should be set to RPGLE so the ILE compiler compiles it correctly when the program is compiled with option 14 from PDM.
This sample can be used to call the Office Integrator to run a MS Word Single Letter Mail Merge.
*-----------------------------------------------------------
C* Sample Single Letter Mail Merge with Office Integrator
*-----------------------------------------------------------
D*** Work Fields
D cmd S 3000 INZ(' ')
D irmtsys S 50 INZ(' ')
D itemplate S 255 INZ(' ')
D ibookmark1 S 30 INZ(' ')
D idata1 S 100 INZ(' ')
D ibookmark2 S 30 INZ(' ')
D idata2 S 100 INZ(' ')
D ibookmark3 S 30 INZ(' ')
D idata3 S 100 INZ(' ')
D ibookmark4 S 30 INZ(' ')
D idata4 S 100 INZ(' ')
D ibookmark5 S 30 INZ(' ')
D idata5 S 100 INZ(' ')
D itextblock S 100 INZ(' ')
D errrtn S 1 INZ(' ')
D*** QUOT is a single quote value
D quot S 1 INZ('''')
*-----------------------------------------------------------
C* MAIN LINE CALCULATIONS
*-----------------------------------------------------------
C*** Entry Parms
C*** Note:
C*** These are commented out since our sample program sets the
C*** values internally. Uncomment the parm fields to pass them
C*** in from another process.
C* *ENTRY PLIST
C* PARM irmtsys
C* PARM itemplate
C* PARM ibookmark1
C* PARM idata1
C* PARM ibookmark2
C* PARM idata2
C* PARM ibookmark3
C* PARM idata3
C* PARM ibookmark4
C* PARM idata4
C* PARM ibookmark5
C* PARM idata5
C* PARM errrtn
C*** Set parm fields for testing
C EVAL irmtsys = '*CURRENT'
C EVAL itemplate= 'C:\Program Files\' +
C 'RJSOFFICE\TESTMEMO.DOT'
C EVAL ibookmark1= 'TO_FIELD'
C EVAL idata1= 'Valued Customer'
C EVAL ibookmark2= 'FROM_FIELD'
C EVAL idata2= 'RJS Software'
C EVAL ibookmark3= 'CC_FIELD'
C EVAL idata3= 'Nobody Else'
C EVAL ibookmark4= 'RE_FIELD'
C EVAL idata4= 'This is an Office ' +
C 'Integrator MS Word Test'
C EVAL ibookmark5= 'SINCERELY_FIELD'
C EVAL idata5= ''
C EVAL itextblock = 'Sincerely<CRLF>James ' +
C 'Johnson<CRLF>President'
*-----------------------------------------------------------
* Build command call to launch MS Word via OLE
* and call it.
*-----------------------------------------------------------
C Eval CMD = 'RJSOFFICE/OFCRUNPC ' +
C 'RMTSYS(' + %trimr(irmtsys) + ') ' +
C 'CMD(' + quot + 'WORDLAUNCH' + quot + ') ' +
C 'OPTION(*WORDOLE)'
* ** Run command string
C call 'QCMDEXC' 56
C PARM CMD
C PARM 3000 LEN 15 5
C* ** Set return code for success or failure
C If *IN56 = *ON
C* ** Error occurred on OFCRUNPC call
C* ** check the joblog for causes
C Eval ErrRtn = '1'
C EVAL *INLR = *ON
C Return
C Else
C* ** Successful
C Eval ErrRtn = '0'
C Endif
*-----------------------------------------------------------
* Build command call to open MS Word template file
* and call it.
*-----------------------------------------------------------
C Eval CMD = 'RJSOFFICE/OFCRUNPC ' +
C 'RMTSYS(' + %trimr(irmtsys) + ') ' +
C 'CMD(' + quot + 'WORDOPENTEMPLATE~' +
C %TRIMR(itemplate) + quot + ') ' +
C 'OPTION(*WORDOLE)'
* ** Run command string
C call 'QCMDEXC' 56
C PARM CMD
C PARM 3000 LEN 15 5
C* ** Set return code for success or failure
C If *IN56 = *ON
C* ** Error occurred on OFCRUNPC call
C* ** check the joblog for causes
C Eval ErrRtn = '1'
C EVAL *INLR = *ON
C Return
C Else
C* ** Successful
C Eval ErrRtn = '0'
C Endif
*-----------------------------------------------------------
* Build command call to insert selected bookmarks in template.
* This is an example of inserting data at multiple bookmark
* locations in a template using a single call to OFCRUNPC.
* The insert bookmark command can be called multiple times
* during the RPG program as needed to add additional bookmarks
* as required.
*-----------------------------------------------------------
C Eval CMD = 'RJSOFFICE/OFCRUNPC ' +
C 'RMTSYS(' + %trimr(irmtsys) + ') ' +
C 'CMD(' + quot + 'WORDINSERTBOOKMARK~' +
C %TRIMR(ibookmark1) + '~' +
C %TRIMR(idata1) + '~' +
C %TRIMR(ibookmark2) + '~' +
C %TRIMR(idata2) + '~' +
C %TRIMR(ibookmark3) + '~' +
C %TRIMR(idata3) + '~' +
C %TRIMR(ibookmark4) + '~' +
C %TRIMR(idata4) + '~' +
C %TRIMR(ibookmark5) + '~' +
C %TRIMR(idata5) + '~' +
C quot + ') ' +
C 'OPTION(*WORDOLE)'
* ** Run command string
C call 'QCMDEXC' 56
C PARM CMD
C PARM 3000 LEN 15 5
C* ** Set return code for success or failure
C If *IN56 = *ON
C* ** Error occurred on OFCRUNPC call
C* ** check the joblog for causes
C Eval ErrRtn = '1'
C EVAL *INLR = *ON
C Return
C Else
C* ** Successful
C Eval ErrRtn = '0'
C Endif
*-----------------------------------------------------------
* Build command call to simply jump to selected bookmark
* so that text can be inserted.
*-----------------------------------------------------------
C Eval CMD = 'RJSOFFICE/OFCRUNPC ' +
C 'RMTSYS(' + %trimr(irmtsys) + ') ' +
C 'CMD(' + quot + 'WORDINSERTBOOKMARK~' +
C %TRIMR(ibookmark5) + '~' +
C quot + ') ' +
C 'OPTION(*WORDOLE)'
* ** Run command string
C call 'QCMDEXC' 56
C PARM CMD
C PARM 3000 LEN 15 5
C* ** Set return code for success or failure
C If *IN56 = *ON
C* ** Error occurred on OFCRUNPC call
C* ** check the joblog for causes
C Eval ErrRtn = '1'
C EVAL *INLR = *ON
C Return
C Else
C* ** Successful
C Eval ErrRtn = '0'
C Endif
*-----------------------------------------------------------
* Build command call to insert text at sincerely bookmark.
* This is a sample simple text insertion at current cursor
* location within a document.
*-----------------------------------------------------------
C Eval CMD = 'RJSOFFICE/OFCRUNPC ' +
C 'RMTSYS(' + %trimr(irmtsys) + ') ' +
C 'CMD(' + quot + 'WORDINSERTTEXT~' +
C %TRIMR(itextblock) + '~' +
C quot + ') ' +
C 'OPTION(*WORDOLE)'
* ** Run command string
C call 'QCMDEXC' 56
C PARM CMD
C PARM 3000 LEN 15 5
C* ** Set return code for success or failure
C If *IN56 = *ON
C* ** Error occurred on OFCRUNPC call
C* ** check the joblog for causes
C Eval ErrRtn = '1'
C EVAL *INLR = *ON
C Return
C Else
C* ** Successful
C Eval ErrRtn = '0'
C Endif
*-----------------------------------------------------------
C* Normal Exit - We're done
*-----------------------------------------------------------
C EVAL *INLR = *ON
C Return
