ILERPG.com β€” IBM i Β· ILE RPG Β· AS400 Mastery
3 min readΒ· Admin

Free-Format RPG Structure: What **FREE Changes, and What It Doesn't

Fixed-format RPG encoded meaning in columns. The letter in column 6 identified the specification type, and every other entry depended on exactly where it sat on the line. Free-format RPG removes that dependency. What it does not remove is the underlying structure of a program: control options, file declarations, data definitions, procedures, and calculations are all still there. They are simply written as keyword-led statements instead of positioned entries.

The **FREE directive

A source member becomes fully free-form when its first line contains **FREE in columns 1 through 6. From that point on, statements may begin in column 1 and extend past column 80, and no fixed-form specification may appear in the member. That last rule is the important one: **FREE is a commitment for the whole member, not a switch that can be turned on and off.

Older releases supported an intermediate style, often called column-limited free form, in which free-form statements were confined to columns 8 through 80 and could be mixed with fixed-form specifications. You will still find it in production code. New code should be written fully free-form.

Mapping the specification types

Each fixed-format specification has a direct free-form counterpart, with two exceptions:

  • H (control) becomes CTL-OPT.
  • F (file) becomes DCL-F.
  • D (definition) becomes DCL-S, DCL-C, DCL-DS, DCL-PR, or DCL-PI.
  • P (procedure) becomes DCL-PROC and END-PROC.
  • C (calculation) becomes an ordinary statement ending in a semicolon.
  • I (input) and O (output) have no free-form equivalent. Data structures and externally described files take over their work.
**free
ctl-opt dftactgrp(*no) option(*srcstmt : *nodebugio);

dcl-f CUSTMAST keyed usage(*input);
dcl-s listed int(10) inz(0);

read CUSTMAST;
dow not %eof(CUSTMAST);
  listed += 1;
  read CUSTMAST;
enddo;

*inlr = *on;
return;

Statements end at the semicolon

A free-form statement is terminated by a semicolon, not by the end of a line. That allows a long condition to be spread over several lines for readability, and it means a missing semicolon joins two lines into one invalid statement. Comments start with // and run to the end of the line. Names are not case-sensitive, so a consistent casing convention is a matter of team discipline rather than compiler enforcement.

The order the compiler expects

A free-form member follows a fixed order: control options first, then global declarations, then the main procedure's calculations, then any subprocedures. Nothing but subprocedures may follow the first DCL-PROC. Every lesson in this series is written in that layout, and it is the layout to expect when you open a modern source member in a production library.

Lesson 13 works through each specification type with fixed-format and free-form versions side by side, and closes with an exercise on PUB400 that examines a real source physical file and compiles a first program on the green screen.

Get the lesson

Lesson 13, β€œFree-Format RPG: Structure, the **FREE Directive, and Spec Types,” is part of Beginner ILE RPG in IBM i ILE RPG Mastery and is available at ILERPG.com for USD 10. The complete Beginner ILE RPG series β€” all 18 lessons β€” is USD 180, or USD 135 with coupon code RPG30, which takes 25% off when you purchase the full series.