Refactoring RPG - Part 1
By Stephen West

Figure 7. All the rest of the stuff you will need!

refactpnl.pnlgrp - Help panel source for the REFACTOR command

:pnlgrp.
:help name=REFACTOR.
Refactor RPGLE Source - Help
:p.
This command assists in refactoring RPGLE by automating some of the
refactoring ideas presented in the SystemiNEWS magazine article
"Refactoring RPG" by Stephen West.
:ehelp.
:help name='REFACTOR/FROMSRC'.
From source
:xh3.From source
:p.
Specify the names of the source physical file and library that contain
the source member to be refactored.

:ehelp.
:help name='REFACTOR/FROMMBR'.
From member
:xh3.From member
:p.
Specify the name of the source physical file member to be refactored.

:ehelp.
:help name='REFACTOR/TOSRC'.
To source
:xh3.To source
:p.
Specify the names of the source physical file and library where the
refactored source member will be placed.

:ehelp.
:help name='REFACTOR/TOMBR'.
To member
:xh3.To member
:p.
Specify the name of the source physical file member where refactored
code will be written.

:ehelp.
:help name='REFACTOR/CLRFSTFIVE'.
Clear the first 5 positions
:xh3.Clear the first 5 positions
:p.
Specifying *YES will put blanks in the first five positions of
all source lines except for compile-time arrays.
:p.
The value of *NO will leave the current contents in the first 5
positions.
:ehelp.
:help name='REFACTOR/CLRFRMTYP'.
Clear form type on comments
:xh3.Clear form type on comments
:p.
Specifying *YES will put a blank in the form type column (column 6)
of comment lines (lines with an * in column 7).
:p.
The value of *NO will leave the current value in the form type
column.
:ehelp.
:help name='REFACTOR/SETDATE'.
Set date
:xh3.Set date
:p.
Set the date on source code lines based on the following
allowed values:
:p.
*SAME - leaves the source dates unchanged.
:p.
*CURRENT - replaces the source dates with the current date.
:p.
*ZEROS - puts all zeros in the source date field.
:ehelp.
:help name='REFACTOR/MIXOPCOD'.
Mixed case opcodes
:xh3.Mixed case opcodes
:p.
Specifying *YES will cause opcodes to be replaced by the versions
in file CSPREMAP.
:p.
The value of *NO will leave the opcodes unchanged.
positions.
:ehelp.
:help name='REFACTOR/LOWBLTINS'.
Lo case %built-ins
:xh3.Lo case %built-ins
:p.
Specifying *YES cause built-in functions to be changed to lower
case.
:p.
  e.g.
    %SUBST becomes %subst
:p.
The value of *NO will leave them unchanged.
:ehelp.
:help name='REFACTOR/LOWFIGCON'.
Lo case figurative constants
:xh3.Lo case figurative constants
:p.
Specifying *YES will cause figurative constants (*BLANK, *ZERO, etc...)
to be changed to lower case.
:p.
The value of *NO will leave them unchanged.
:ehelp.
:help name='REFACTOR/CVTCMT2BLK'.
Convert plain comment to blank
:xh3.Convert plain comment to blank
:p.
Specifying *YES will blank out the asterisk from the comment
column (7) when positions 8 through the end of the line are blank.
:p.
The value of *NO will leave asterisk in the comment column.
:ehelp.
:help name='REFACTOR/UPDCONDS'.
Update conditionals
:xh3.Update conditionals
:p.
Specifying *YES will cause conditionals to be moved out of the
opcode they are embedded in and into the factor 2 area.
:p.
e.g.    Factor1+++++++Opcode&ExtExtended-factor2
:p.
This:   FACT1         IFGT      FACT2
:p.
Becomes:              IF        FACT1 > FACT2
:p.
The value of *NO will leave them alone.
positions.
:ehelp.
:help name='REFACTOR/RMVHILITES'.
Remove hilites
:xh3.Remove hilites
:p.
Specifying *YES will put a blank in any character that contains
a non-printable hexadecimal value.  Some PC-based source code
editors do not handle non-printable hexadecimal values.
:p.
The value of *NO will leave the hexadecimal values alone.
:ehelp.
:epnlgrp.
  


remapdata.txt - Data for the CSPREMAP table

CLLE      ADDLIBLE  AddLible
CLLE      CALL      Call
CLLE      CHGDTAARA ChgDtaAra
CLLE      CHGVAR    ChgVar
CLLE      CPYF      CpyF
CLLE      DCL       DCL
CLLE      DO        Do
CLLE      ELSE      Else
CLLE      ENDDO     EndDo
CLLE      ENDFOR    EndFor
CLLE      ENDPGM    EndPgm
CLLE      FOR       For
CLLE      IF        If
CLLE      MONMSG    MonMsg
CLLE      PGM       Pgm
CLLE      RETURN    Return
CLLE      RTVJOBA   RtvJobA
CLLE      SNDPGMMSG SndPgmMsg
CLLE      SNDRCVF   SndRcvF
RPGLE     ADD       Add
RPGLE     ADD(H)    Add(H)
RPGLE     BEGSR     BegSr
RPGLE     BITOFF    BitOff
RPGLE     BITON     BitOn
RPGLE     CALL      Call
RPGLE     CALLP     CallP
RPGLE     CAT       Cat
RPGLE     CHAIN     Chain
RPGLE     CHAIN(N)  Chain(N)
RPGLE     CHECK     Check
RPGLE     CHECKR    CheckR
RPGLE     CLEAR     Clear
RPGLE     CLOSE     Close
RPGLE     DELETE    Delete
RPGLE     DIV       Div
RPGLE     DIV(H)    Div(H)
RPGLE     DO        Do
RPGLE     DOU       DoU
RPGLE     DOW       DoW
RPGLE     ELSE      Else
RPGLE     END       End
RPGLE     ENDCS     EndCs
RPGLE     ENDDO     EndDo
RPGLE     ENDFOR    EndFor
RPGLE     ENDIF     EndIf
RPGLE     ENDSL     EndSl
RPGLE     ENDSR     EndSr
RPGLE     EVAL      Eval
RPGLE     EVAL(H)   Eval(H)
RPGLE     EXCEPT    Except
RPGLE     EXFMT     ExFmt
RPGLE     EXSR      ExSr
RPGLE     FOR       For
RPGLE     GOTO      GoTo
RPGLE     IF        If
RPGLE     KFLD      KFld
RPGLE     KLIST     KList
RPGLE     LEAVE     Leave
RPGLE     LOCK      Lock
RPGLE     LOOKUP    LookUp
RPGLE     MOVE      Move
RPGLE     MOVEA     MoveA
RPGLE     MOVEL     MoveL
RPGLE     MULT      Mult
RPGLE     MULT(H)   Mult(H)
RPGLE     OCCUR     Occur
RPGLE     OPEN      Open
RPGLE     OTHER     Other
RPGLE     PARM      Parm
RPGLE     PLIST     PList
RPGLE     READ      Read
RPGLE     READC     ReadC
RPGLE     READ(N)   Read(N)
RPGLE     READE     ReadE
RPGLE     READE(N)  ReadE(N)
RPGLE     READP     ReadP
RPGLE     READP(N)  ReadP(N)
RPGLE     RESET     Reset
RPGLE     RETURN    Return
RPGLE     SELECT    Select
RPGLE     SETLL     SetLL
RPGLE     SETOFF    SetOff
RPGLE     SETON     SetOn
RPGLE     SORTA     SortA
RPGLE     SUB       Sub
RPGLE     SUB(H)    Sub(H)
RPGLE     TAG       Tag
RPGLE     TIME      Time
RPGLE     UNLOCK    UnLock
RPGLE     UPDATE    Update
RPGLE     WH        Wh
RPGLE     WHEN      When
RPGLE     WRITE     Write
RPGLE     Z-ADD     Z-Add
RPGLE     Z-ADD(H)  Z-Add(H)
RPGLE     Z-SUB     Z-Sub
RPGLE     Z-SUB(H)  Z-Sub(H)


setup.clle - Program to build everything

/********************************************************************/
/* Refactoring RPG - Part 1 by Stephen West                         */
/* Setup objects for Refactoring RPGLE Source tool                  */
/********************************************************************/
Pgm (&pmLibrary)
    Dcl &pmLibrary                    *char 10

    Dcl &pvSysName                    *char 8
    Dcl &pvPath                       *char 128

    /* Make sure that QTEMP is at the top of the library list. */
    RmvLibLE QTEMP
    MonMsg CPF0000
    AddLibLE QTEMP
    MonMsg CPF0000

    /* Make sure that &pmLibrary is right after QTEMP. */
    RmvLibLE &pmLibrary
    MonMsg CPF0000
    AddLibLE &pmLibrary
    MonMsg CPF0000

    /* Create objects into target library. */
    DltMsgF MsgF(&pmLibrary/CSMSGF)
    MonMsg CPF0000
    CrtMsgF MsgF(&pmLibrary/CSMSGF)
    AddMsgD MsgId(CSM0001) MsgF(&PMLIBRARY/CSMSGF) Msg('&1') Fmt((*CHAR 256))
    DltF File(&pmLibrary/CSPFIELDS)
    MonMsg CPF0000
    CrtPF File(&pmLibrary/CSPFIELDS) +
             SrcFile(&pmLibrary/REFSRC) SrcMbr(CSPFIELDS)
    DltF File(&pmLibrary/CSPREMAP)
    MonMsg CPF0000
    CrtPF File(&pmLibrary/CSPREMAP) +
             SrcFile(&pmLibrary/REFSRC) SrcMbr(CSPREMAP)
    CpyF FromFile(&pmLibrary/REFSRC) ToFile(&pmLibrary/CSPREMAP) +
             FromMbr(REMAPDATA) ToMbr(*FIRST) +
             MbrOpt(*REPLACE) FmtOpt(*CVTSRC)
    CrtBndRPG Pgm(&pmLibrary/CS8801) Replace(*YES) +
             SrcFile(&pmLibrary/REFSRC) SrcMbr(CS8801)
    CrtBndCL Pgm(&pmLibrary/CSC8801) Replace(*YES) +
             SrcFile(&pmLibrary/REFSRC) SrcMbr(CSC8801)
    CrtPnlGrp PnlGrp(&pmLibrary/REFACTPNL) Replace(*YES) +
             SrcFile(&pmLibrary/REFSRC) SrcMbr(REFACTPNL)
    CrtCmd Cmd(&pmLibrary/REFACTOR) Replace(*YES) PrdLib(&pmLibrary) +
             Pgm(*LIBL/CSC8801) +
             SrcFile(&pmLibrary/REFSRC) SrcMbr(REFACTOR) +
             HlpPnlGrp(*LIBL/REFACTPNL) HlpId(REFACTOR)

    GoTo ExitPgm /* Normal termination */

 /*==================================================================*/
  ExitPgm:
    Return
EndPgm

� 2007 Workware, Inc. All rights reserved.