In brief
Converting RPG to free-form means rewriting a program from fixed-column format into free format without changing what it does. Tools (commands in RDi and commercial converters) do most of the mechanical work, but they do not safely carry over MOVE operations, indicators, GOTO statements and I/O specifications. Work program by program, start with the ones that change most often, keep the conversion in a separate commit from logic changes, and verify every program with a comparison test: the same input, the same results.
What changes and what stays
RPG IV has allowed declarations and calculations in free format for years. The **FREE directive on the first line means the whole source member is fully free-form, with no columns at all. IBM lists it in the changes for release 7.3. Input and output specifications (I and O) and the TAG operation cannot be written in free format: if you need them, they go into a separate member included with /COPY.
A small program before conversion:
FKLIENCI IF E K DISK
D Saldo S 11P 2
C *ENTRY PLIST
C PARM NRKL 7 0
C KLUCZ KLIST
C KFLD NRKL
C KLUCZ CHAIN KLIENCI 90
C *IN90 IFEQ *OFF
C Z-ADD KLSALDO Saldo
C ENDIF
C SETON LRAnd after conversion:
**FREE
dcl-f klienci keyed;
dcl-s saldo packed(11: 2);
dcl-pi *n;
nrkl packed(7: 0);
end-pi;
chain nrkl klienci;
if %found(klienci);
saldo = klsaldo;
endif;
*inlr = *on;The program does the same thing (it looks up a customer and reads the balance), but indicator 90 no longer turns on. If another part of the program or a display file relies on it, the result changes. This is a typical pitfall, covered below.
Tools: what they convert on their own
| Tool | What it does well | What to watch for |
|---|---|---|
| Conversion commands in RDi | calculations and some declarations, scope depends on the version | mixed results: part of the code can stay in columns |
| VS Code with the Code for IBM i extension | editing, compiling and git work on new code | the extension itself is not a converter, check results like any others |
| Commercial tools | full H, F, D and P declarations, a report of what was not converted | licensing, configuring naming rules |
| Rewriting by hand | full control, cleanup along the way | time, and the risk of mistakes without a test |
No tool knows the author's intent. A converter will rewrite MOVE as an expression, but it does not know whether the author meant to move only part of the field. So treat the tool's output as a draft that goes through review and testing.
Constructs that need attention
| Fixed format | Free-form equivalent | Pitfall |
|---|---|---|
| MOVE, MOVEL | assignment with %SUBST, %CHAR, %DEC, %EDITC | MOVE right-aligns and leaves the rest of the field unchanged |
| Resulting indicators on CHAIN, READ | %FOUND, %EOF, %ERROR | the indicator is used later in the program or in a display file |
| Conditioning indicators in columns 9–11 | IF before the statement | several indicators at once, combined with AND and OR over several lines |
| CALL with PARM | a prototype and CALLP | parameter types and lengths must match |
| *ENTRY PLIST | DCL-PI | optional parameters passed by a CL program |
| KLIST, KFLD | a key list in parentheses or %KDS | the order of key fields |
| GOTO, TAG | loops and procedures | TAG does not exist in free format, so the structure must change |
| Z-ADD, ADD with half adjust | assignment with (H) | a missing (H) changes the result by a cent |
Programs that set indicators used in 5250 display files and in subroutines need particular care. Before converting, write down where each indicator is set and where it is read. A program description produced with a language model helps here, with the caveats in Documenting RPG code with AI.
Order of work
- Sources in git. Converting without change history is risky, because you cannot easily compare versions. How to move the sources is covered in Git and CI/CD for IBM i.
- A list of programs by change frequency. Start with the ones the team changes every month. Programs nobody has touched for years can stay in fixed format.
- /COPY members separately. Shared prototypes and data structures are converted with every program that includes them in mind.
- One program, one commit. Conversion without logic changes, with a compile and a test. Logic changes go in a separate commit.
- Code review. A second person compares the versions and checks the spots from the table above.
- Deploy with a regular change. A converted and tested program goes to production with the next business change or in a separate release.
How to prove nothing changed
A clean compile does not prove the program behaves the same. A comparison test does:
- the same input for the old and the new version, on a copy of the test libraries;
- comparing the results: file contents after the run, reports, messages and indicators returned to the calling program;
- edge cases: record not found, empty field, negative value, maximum field length, end of file.
The tests written during conversion stay in the repository and protect the program during later changes. How to build such tests on IBM i is covered in Automated tests for IBM i applications, and what modern RPG looks like after conversion in RPG today.
Conversion makes sense as part of ongoing work on the system, in the release rhythm you already have, with code review and tests. That is the scope of Application development: B2Bnetwork engineers work in your repository and to your definition of done.
Questions and answers
Does converting to free-form change how the program behaves?
It should not, but it can if the conversion is careless. The most common sources of differences are MOVE on fields of different lengths, indicators that stop turning on and a missing half adjust. That is why every converted program goes through a comparison test on the same data as the version before conversion.
Do we have to convert all programs at once?
No. Programs in both formats run side by side and can call each other. A sensible approach is to convert the programs the team changes often and leave old, stable programs alone. Whole applications are rarely converted, and usually only when other work comes with it.
How long does it take to convert an RPG program?
It depends on the program's length and the number of difficult constructs. A simple program after a tool pass mostly needs review and testing. A program with many indicators, GOTOs and MOVEs between fields of different lengths needs manual work. A trial conversion of a few typical programs gives you an estimate.
Will younger developers learn the code faster after conversion?
Usually yes, because free format resembles other languages and the names and structure are easier to read. Conversion alone is not enough when the logic is tangled, though. The biggest gain comes from combining conversion with a program description and tests that show what the program does.