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

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

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

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

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

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

remapdata.txt - Data for the CSPREMAP table

CLLE      ADDLIBLE  AddLible
CLLE      CALL      Call
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
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     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 */


� 2007 Workware, Inc. All rights reserved.