CVTILEFMT: A Beautician Specializing in RPG IV Source Code
Converting RPG III source to RPG IV source has never been as easy as this. By using CVTILEFMT after using IBMs CVTRPGSRC command, you will save time and money and make your code more readable by taking advantage of RPG IVs free-format operands.
Many of us have undoubtedly started working on projects that we allocated time for in this new year. One of the projects most of us have been meaning to start is converting our RPG III source to RPG IV, and possibly throwing in a hint of ILE. This project as a whole may seem overwhelming, but when it is broken down into steps, its really nothing more than doing the same task over and over again.
IBM aids you with this conversion by supplying the Convert RPG Source (CVTRPGSRC) command. CVTRPGSRC performs an uncomplicated conversion of an RPG III source member to RPG IV. This is a great start, but CVTRPGSRC doesnt take advantage of the free-format expressions we have been waiting eagerly to use. Thats where Convert ILE Format (CVTILEFMT) comes in. CVTILEFMT picks up where CVTRPGSRC leaves off by converting your source to use the free-format style and by performing a couple of other conversions to make your code more understandable. After running CVTRPGSRC, run CVTILEFMT on your source member and enjoy your new free-formatted source.
I created CVTILEFMT a few years ago when I was part of a team converting homegrown software to RPG IV. We wanted to take full advantage of the free-format expressions now available to us but found converting all of the source by hand time- consuming. I wrote CVTILEFMT to take care of these concerns. CVTILEFMT worked so well on our code that I made it available to others. Since then, CVTILEFMT has been tested and tweaked using suggestions from the many people who found it useful. (Find the CVTILEFMT utility on the MC Web site at www.midrangecomputing.com/mc/99/03.)
What CVTILEFMT Will Do for You
CVTILEFMT, when run on source after IBMs CVTRPGSRC command, will do the following:
Convert expressions such as IFs, DOs, and WHENs to free-format expressions. Parentheses also are added to make the expressions more readable.
Convert arithmetic expressions to free-format EVALs. Each mathematical operand (ADD, MULT, DIV, SUB) can be converted or left as is. The reason for providing this choice is that sometimes you wont want to convert certain statements. This is because, if you do otherwise, the statement may perform some unwanted task, such as date flipping. Arithmetic conversion is controlled by the CVTxxx parameters, where xxx is ADD, SUB, MULT, or DIV.
Move all C-spec defined variables into the D-specs, alphabetically. If a variable is defined on a C-spec, the declaration is removed and placed in the D-specs.
Format all END statements, converting them to their proper form (ENDIF, ENDDO, etc.) This capability comes in handy in cases where programmers coded only END for DOs, IFs, CASEs, and SELECTs. This change increases the ease of tracing the program, whether in SEU or while debugging.
Convert the source (excluding comments, constants, and table data) to all uppercase or all lowercase. Depending on what you specify on the Uppercase or lowercase (UPLOW) parameter, your source will be converted to uppercase or lowercase.
What CVTILEFMT Will Not Do for You
CVTILEFMT will not convert MOVE statements. This is because MOVE can be used to move data of one type to a field of another type. Also, if you previously used resulting indicators on mathematical operations and you convert these operations to EVALs, the resulting indicators will be lost. This is a good time to convert these less-used methods into more readable code and also eliminate the use of confusing indicators.
How It Works
CVTILEFMT consists of five objects, listed in Figure 1. The CL program FMT001CL handles command validation. The program checks to make sure that the source member specified on the CVTILEFMT command exists and that it is either of type RPGLE or SQLRPGLE. Then, FMT001CL will make sure that the libraries you specified on both the To and From parameters are in your library list. If they are not, those parameters are added, and a flag is set to remove the libraries from your library list after CVTILEFMT is complete. Control is then passed to the main processing program, FMT001RG.
FMT001RG first reads one line of source at a time. For each line of source, FMT001RG first determines if the line of source needs to be converted. If the current line of source is one that can be converted, it then uses a simple table of RPG operands to decide what to do with the statement. FMT001RG then formats a new free-form expression by using information gathered from the old expression. If, during this processing, a variable is found that is declared on the C-spec statement, FMT001RG adds this field to an array to be added to the D-specs.
FMT001CL then calls the second RPG program, FMT002RG, to resequence the source and convert to uppercase or lowercase. Case translation is done character by character. This process occurs so that special attention can be taken so as not to convert literal data inside of quotation marks, comments, or table data located at the bottom of the source. After FMT002RG completes, it passes control back to FMT001CL where a completion message is sent to the user telling them that the conversion is complete.
An Ounce of Precaution
When using CVTILEFMT for the first time, it is best to be cautious. CVTILEFMT does all it can to help you from accidentally overwriting source that already exists. But, CVTILEFMT will not allow you to convert your source into the same member or into a member that already exists unless you specify to do so on the command. You can achieve this conversion by specifying a *YES on the Replace member (RPLMBR) parameter of the CVTILEFMT command. This parameter defaults to *NO so you wont accidentally
overwrite an existing member. I suggest you convert and compile your source into a library other than your production library and thoroughly test the programs before moving them into production.
More Power to You
I hope you find CVTILEFMT as helpful and timesaving as we did at our company. If you like it, you may want to create a PDM option like the one in Figure 2.
Just as you create business application programs that save users time, you can use those same skills to write programs that perform even the most tedious of chores. Although it takes time to develop tools like CVTILEFMT, the time saved most certainly makes up for it.
Object Type Function
CVTILEFMT CMD Command interface for CVTILEFMT utility FMT001CL CLP Command processing program FMT001PG PNLGRP Help text
FMT001RG RPGLE Converts RPG IV source code FMT002RG RPGLE Converts to uppercase or lowercase
Figure 1: The CVTILEFMT utility consists of five objects.
CVTILEFMT FROMFILE(&L/&F) FROMMBR(&N) +
TOFILE(&L/QRPGLESRC) TOMBR(*FROMMBR) +
RPLMBR(*YES)
Figure 2: Creating a handy PDM option, such as this one, makes CVTILEFMT even easier to use.
LATEST COMMENTS
MC Press Online