Here is a utility command that will become invaluable in your programmers toolbox: the Indent RPG command. It shows RPG code (any flavor) indented to reveal logic blocks. You can direct the output to the screen or the printer!
Maintenance programmers dont lead easy lives. I should know because maintenance programming is what I do most of the time. If youre like me, you recognize this scenario: Someone asks you to make a tiny modification to a program. You start SEU to edit the program only to discover that it has complex logic blocks indented one inside another several levels deep.
If RPG were a free-format language, you could identify the start and end of each block by indentation. But because RPG is a fixed-format language, indentation is not an option.
In this article, I present another method, made possible by the Indent RPG (INDRPG) command. Although the code of this command is too lengthy to publish here, it is available on the Web at www.midrangecomputing.com/mc/99/06.
Before you yell at me because CRTRPGPGM, CRTBNDRPG, and CRTRPGMOD offer an Indent parameter, let me tell you something about that. The CRTxxx commands never show the indented code on the screen, so you cannot perform searches. They require you to recompile, which may be too slow or altogether impossible (e.g., if some of the files used by the program are not online). INDRPG doesnt have these shortcomings.
INDRPG Revealed
INDRPG presents RPG code in a readable fashion and can indent RPG III or IV code (and accepts either uppercase or lowercase for the latter).
The INDRPG command has nine parameters:
Source file (SRCFILE) identifies the source file containing the member to be indented. The library qualifier defaults to *LIBL. You can also specify a library name or *CURLIB. Source member (SRCMBR) identifies the source member to be indented.
Subroutine name (SUBR) tells INDRPG which subroutine to indent. The default value, *ALL, processes the entire program. You can type the name of a single subroutine or the
special value *MAIN to list the programs mainline (the portion of the C-specs before the first BEGSR).
Output (OUTPUT) determines whether the indented code should be displayed (*) or printed (*PRINT).
Columns per level (COLS) determines how many columns to the right to shift code. The default value is 2.
Symbol for indentation (SYMBOL) determines which symbol to use to join the beginning and end of a logic block. The default is a vertical bar.
Ignore commented-out C-specs (IGNCMTOUT) omits all C-specs that have been commented out (i.e., those that have an asterisk in column 7 but contain actual RPG code) when you use the default value of *YES.
Ignore top comments (IGNTOPCMT) omits all the comments located at the top of the program if you use the default value of *YES.
Display size (DSPSIZ) formats the screen display size. If you have a display station capable of showing 27 lines by 132 columns, take advantage of its extended area by specifying *WIDE.
What INDRPG Does for You
INDRPG displays or prints the following items:
The source sequence number
The indented source code
The word LABEL to the left of lines containing labels (such as TAG, BEGSR, or ENDSR)
The markers HI, LO, and EQ to the right of the code, identifying the resulting indicators coded in C-specs
The date each record was last changed Because a 24-line by 80-column display station has less room for displaying data, only the indented source code is presented in this format. You can display the remaining pieces of information, as you will see shortly. Comments are displayed in blue, making it easier to distinguish between live code and comments (including commented-out code). INDRPG displays (or prints) a solid line of dashes right before each BEGSR op code and each RPG IV subprocedure.
Any Other Tricks?
When INDRPG sends the output to the screen, you can take advantage of four input fields located at the top of the display. The first field controls how many lines are rolled each time you press the Page keys. By default, INDRPG rolls 25 lines in 27 by 132 mode and 23 lines in 24 by 80 mode. You can change this value to anything between 1 and 9999. The second field allows you to go directly to any given label in the program, whether its a TAG, BEGSR, ENDSR, or subprocedure. The third field lets you go directly to any line of the source member. Just remember to press Field Exit after typing the sequence number (without the decimal point). For instance, to go to line 17.50, type 1750, press Field Exit, and then press Enter. The fourth field lets you go directly to a number of special points within the source member, all of which are identified by a letter. These special points are as follows:
Top of program (T)
Bottom of program (B)
Beginning of F-specs (F)
Beginning of E-specs (E)
Beginning of I-specs (I)
Beginning of C-specs (C)
Beginning of O-specs (O)
Beginning of D-specs (D) You can also press F4 to open a window listing all labels. When you move the cursor to one of these labels and press Enter, its name is automatically placed in the Go to label input field previously described. Pressing Enter a second time positions the subfile to that label. As in
SEU, pressing the F21 key displays a command line window. (You dont need to memorize any of this. Press the Help key, and an information panel shows up.)
There are three more function keys you can use. First, you can press F13 to change the values you provided for several of the INDRPG commands parameters. Second, the F14 key invokes SEU. Third, the F24 key provides useful information about the source member youre looking at.
Another useful feature is that you can move the cursor to any subfile line and press Enter to display a window of additional information about that source line. You will see the sequence number, the date of last change, the name of the current subroutine or subprocedure, and the indicator usage. In the 27 by 132 format, most of this information is always displayed. This feature of the Enter key is most advantageous when you are using the 24 by 80 format.
Of Needles and Haystacks
No source code browser would be complete without a Find feature. When you press F5, INDRPG opens up a window in which you can type the following Find options:
One, two, or three strings that you want to locate. If any of them is found, INDRPG positions the subfile so that the string is at the top of the listing. By having three input fields, you can find a particular variable or file even if you dont remember its exact name. Was it CUSMAS, CUSTMAS, or CUSTMAST? No matter, just type all three and see what you get.
An input field in which you indicate where to look for the strings. By default, this field contains a C, which means anywhere in the code. You can change it to any of the following values:
L (to search in the left 5 columns of each line, since many programmers code revision identifiers there)
D (date last changed)
F1 (factor 1)
OC (op code)
F2 (factor 2)
RF (result field)
CM (comments)
Whether or not to ignore case differences. The default is to ignore case.
Where to start the search. This field has a C (current) by default, which means the search begins with the source line at the top of the screen. You can also request that the search begin at the top (T) or bottom (B) of the member.
Di rect ion of t he s earc h. Its dow nwar d (D ) by def ault , bu t yo u ca n ch ange it to upw ard (U). Not e th at i f yo u st art the sear ch a t th e to p (T ), t he d irec tion of the se arch is alwa ys a ssum ed t o be dow nwar d (D ), e ven if y ou e nter U f or d irec tion . In co ntra st, star ting the sea rch at t he b otto m fo rces the dir ecti on u pwar d.
So far, youve found only the first occurrence of the string. To find the next (or previous) occurrence, press F9 (or F8). Regardless of the direction of search you have indicated, F9 always looks for the next occurrence going down, and F8 always looks going up.
Implementation Notes
INDRPG is most useful in a display station capable of showing 27 lines by 132 columns, but you can use the regular 24 by 80 display station, too. If you are like most programmers and use PC workstations with Client Access/400 (or a similar program), you can configure a 27 by 132 device without trouble.
The IGNCMTOUT feature forced me to hardcode the names of all valid operation codes in both RPG III and IV, which are listed in compile-time data at the bottom of program INDRPGR. (There are 173 op codes; can you believe that?) This list is complete as of V4R2. If later releases of the language add more op codes, youll have to change that list.
Finally, CL program INDRPGC uses utility command Forward Program Messages (FWDPGMMSG), which was published in my article How to Forward Messages in CL in the January 1998 issue of MC.
I think you will find INDRPG a useful tool, one that has several features you cant get from SEU or from an indented compiler listing. If you have comments or suggestions for improvements, Id love to hear from you.
Reference
How to Forward Messages in CL, MC, January 1998
LATEST COMMENTS
MC Press Online