PreviousNext
Help > Programming with LAUNCHER Office > Advanced programming > RPG programs samples > Word example
Word example

 The principle of this example is to fill in an order table.

 

We placed a bookmark at the first cell of the table that will receive data (on the second line, the first one is reserved for the table’s header).

So, the program will create a document based on a template, write data for the document’s header, and fill in the table (it uses the WSETLINE command).

 

The table contains only one line, because Word will automatically grow the table, once you are in the right-most cell (and the last one) and you want to go to the next cell.

This means that we will not have any blank lines.

 

The text field that follows the table will shift down as we fill in the table.

 

The empty document is as follows (the bookmark indicators are on) :

 

Word program source (in RPG language)

 

*******************************************************************

* Files used :       SP_CUST --> Customers file                   *

*                   SP_ORD_ID --> Logical file on ORDERS file     *

*                   SP_DET_OR --> Logical file on DETAIL file     *

*******************************************************************

     FSP_CUST   if   e           k disk

     FSP_ORD_ID if   e           k disk

     FSP_DET_OR if   e           k disk

 

*******************************************************************

* Declaration of the variables used by LAUNCHER/400. Take a look  *

* at the user's guide to know how to use them.                    *

*******************************************************************

     DHANDLE           s             50    inz('*ONLY')

     DSVRADDR          s             30    inz('*DEV')

     DCCSID            s             10    inz('*JOB')

     DLNCCMD           s             10    inz(*blanks)

     DLNCPARM1         s            512    inz(*blanks)

     DLNCPARM2         s           1024    inz(*blanks)

     DLNCOPT           s              1    inz(*blanks)

     DLNCRESULT        s            512    inz(*blanks)

 

*******************************************************************

* Variables used by the program                                   *

*******************************************************************

     DPREMIER          s              9    inz(*blanks)

     DDATECMD          s               d   datfmt(*EUR)

     DDATECMDS         s             10    inz(*blanks)

     DPRIXUP           s              8p 0 inz(0)

     DPRIXTP           s              8p 0 inz(0)

     DPRIXU            s              8    inz(*blanks)

     DPRIXT            s              8    inz(*blanks)

     DQTE              s             10    inz(*blanks)

     DRECORD           s              9

 

*******************************************************************

* Program entry point, defining parameters                        *

*******************************************************************

     C     *ENTRY        PLIST

     c     premier       PARM                    record

*

* Show the screen and the data corresponding to the parameters

*

     C     PREMIER       chain     SP_CUST                       90

*

* Connecting to LAUNCHER/400. The server is addressed by the 

* variable SVRADDR. *DEV means that the server is the who emulates

* the screen (when using a 5250 emulation screen).

*

     c                   call      'LNCOPEN'

     c                   parm                    handle

     c                   parm                    svraddr

     c                   parm                    ccsid

 

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

* Edits a sales document that will be sent by e-mail

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

     c                   eval      lnccmd='WORDOPEN'

     c                   exsr      CALLLNC

     c                   eval      lnccmd='WMINIMIZE'

     c                   exsr      CALLLNC

* Creates a new document based on a template

     c                   eval      lnccmd='WNEWFILE'

     c                   eval      lncparm1=''+

     c                             '\Letter.dot'

     c                   exsr      CALLLNC

     c                   eval      lnccmd='WMINIMIZE'

     c                   exsr      CALLLNC

* Using bookmarks, data are set in the document

     c                   eval      lnccmd='WBOOKMARK'

     c                   eval      lncparm1='FNAME'

     c                   eval      lncparm2=

     c                   exsr      CALLLNC

     c                   eval      lncparm1='LNAME'

     c                   eval      lncparm2=

     c                   exsr      CALLLNC

     c                   eval      lncparm1='ADDRESS'

     c                   eval      lncparm2=

     c                   exsr      CALLLNC

     c                   eval      lncparm1='ZIP'

     c                   eval      lncparm2=

     c                   exsr      CALLLNC

     c                   eval      lncparm1='CITY'

     c                   eval      lncparm2=

     c                   exsr      CALLLNC

     c                   eval      lncparm1='STATE'

     c                   eval      lncparm2=

     c                   exsr      CALLLNC

     c                   eval      lncparm1='PHONE'

     c                   eval      lncparm2=

     c                   exsr      CALLLNC

     c                   eval      lncparm1='FAX'

     c                   eval      lncparm2=

     c                   exsr      CALLLNC

     c                   eval      lncparm1='EMAIL'

     c                   eval      lncparm2=

     c                   exsr      CALLLNC

* Small routine to show the orders of the customer.

* We go on the order's file

     c     cust_id       setll     sp_ord_id

     c     cust_id       reade     sp_ord_id                     91

     c   91              goto      Fin

* On the document, go to the table

     c                   eval      lnccmd='WBOOKMARK'

     c                   eval      lncparm1='TABLE'

     c                   eval      lncparm2=

     c                   exsr      CALLLNC

     c     loop_order    tag

     c                   move      ORDER_DATE    datecmd

     c                   movel     datecmd       datecmds

* Then, go to the order's detail

     c     order_id      setll     sp_det_or

     c     order_id      reade     sp_det_or                     92

     c   92              goto      Suite

     c     loop_detail   tag

     c                   eval      lnccmd='WSETLINE'

     c                   eval      lncparm1= + '%SEP%' 

     c                             + PART_DESC

     c                   exsr      CALLLNC

     c                   eval      PRIXUP=

     c                   movel     prixup        prixu

     c                   eval      lnccmd='WBOOKMARK'

     c                   eval      lncparm1='''*RIGHT'' ''NUMFMT(0)'' '

     c                   eval      lncparm2=

     c                   exsr      CALLLNC

     c                   movel(p)  QUANTITY      QTE

     c                   eval      lncparm2=

     c                   exsr      CALLLNC

     c                   eval      PRIXTP=

     c                   movel     prixtp        prixt

     c                   eval      lncparm2=

     c                   exsr      CALLLNC

* We read next detail from the order

     c     order_id      reade     sp_det_or                     92

     c  N92              eval      lncparm1='*RIGHT'

     c  N92              eval      lncparm2=

     c  N92              exsr      CALLLNC

     c  N92              goto      loop_detail

     c     Suite         tag

* And here, the next order

     c     cust_id       reade     sp_ord_id                     93

     c  N93              eval      lncparm1='*RIGHT'

     c  N93              eval      lncparm2=

     c  N93              exsr      CALLLNC

     c  N93              goto      loop_order

* All data are set, wa can save and send it

     c     Fin           tag

     c                   eval      lnccmd='WSAVEAS'

     c                   eval      lncparm1='%LNCDIR%\samples\' +

     c                             firstname + '.doc'

     c                   eval      lncparm2=

     c                   exsr      CALLLNC

     c                   eval      lnccmd='WSENDTO'

     c                   eval      lncparm1=

* The next line is not executed, preventing from abusive mail

*    c                   exsr      CALLLNC

     c                   eval      lnccmd='WMAXIMIZE'

     c                   exsr      CALLLNC

      * Exiting from the Launcher server

     c                   eval      lnccmd='END'

     c                   exsr      CALLLNC

     c                   call      'LNCCLOSE'

     c                   parm                    HANDLE

     c                   seton                                   lr

 

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

* SUB CALLLNC : This sub-routine send the command to the LAUNCHER/400

*    server. The different parameters are already set by main

*    program. For more information, take a look at the user's manual

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

     c     CALLLNC       BEGSR

     c                   call      'LNCCMD'

     c                   parm                    HANDLE

     c                   parm                    LNCCMD

     c                   parm                    LNCOPT

     c                   parm                    LNCPARM1

     c                   parm                    LNCPARM2

     c                   parm                    LNCRESULT

     c                   ENDSR