In brief
Today's RPG is a procedural language with a readable free-form syntax, procedures, modules, and SQL written directly in the code. You write code in VS Code with the Code for IBM i extension or in RDi, keep it in git, and compile from sources in the IFS. Old fixed-column RPG and the SEU editor still exist in many companies, but new code does not have to look like that, and a Java or C# developer can read it without a translator.
From columns to free-form
For decades RPG was a column-based language: what mattered was which column a character sat in, and the logic was driven by indicators from *IN01 to *IN99. Code in this form still runs and still has to be read, but for years it has not been the only way to write.
The changes came in stages:
| Stage | What it brought |
|---|---|
| RPG IV (ILE RPG), 1990s | Longer names, procedures, modules, and service programs in the ILE environment |
| Version V5R1 | Calculation blocks in free format (/free … /end-free) |
| IBM i 7.1 TR7 | Declarations in free format: ctl-opt, dcl-s, dcl-f, dcl-proc |
| IBM i 7.2 TR3 | Fully free format (**FREE): no columns, code from the first column |
In practice this means a new program may have no column-based specifications at all. Old code can be moved over gradually, procedure by procedure, because the compiler accepts both styles in one source if you do not use **FREE.
What modern code looks like
Below is a procedure in a service program. There are no indicators or columns here, just a return type, a read-only parameter, and ordinary control statements.
**free
ctl-opt nomain;
dcl-proc obliczRabat export;
dcl-pi *n packed(9:2);
kwota packed(9:2) const;
end-pi;
if kwota >= 1000;
return kwota * 0.05;
endif;
return 0;
end-proc;SQL is written directly in the code (a source file of type SQLRPGLE), with program variables preceded by a colon:
**free
dcl-s nazwa varchar(40);
dcl-s nrKlienta packed(7:0) inz(1001);
exec sql
select trim(nazwa) into :nazwa
from klienci
where nrkl = :nrKlienta;
if sqlcode = 0;
dsply nazwa;
endif;
*inlr = *on;Good teams write small procedures in service programs and access data through SQL instead of record operations scattered in many places at once. Such code is easier to test and to expose as a service for other systems.
Tools: VS Code, RDi, and git
The SEU editor, known from the green screen, does not recognize the new syntax and no longer makes sense for new code. Two mature options remain.
- VS Code with Code for IBM i. An open extension developed on GitHub (the codefori project). It provides browsing of libraries and the IFS, source editing, compilation with the error list shown next to the code, RPG syntax hints, and a connection to the Db2 for i database. For developers who know VS Code from other languages, this is the shortest path.
- RDi (Rational Developer for i). IBM's commercial environment based on Eclipse, with the LPEX editor, a debugger, and code analysis tools. Many teams have worked in it for years and have no reason to change that.
Whichever editor you use, it is worth moving the sources to git. The compiler accepts files from the IFS, for example through the SRCSTMF parameter of the CRTBNDRPG and CRTRPGMOD commands, so the source can sit in a repository like in any other project. Then a change goes through code review, and the history does not vanish along with a backup library.
Git also changes how the team works. Each developer can have a personal working library to compile their branch into, and the job's library list decides whether a test uses the new version of a program or the one in production. This way two people change the same module without overwriting each other's work, and deployment means compiling the approved version from the repository, not copying objects between libraries by hand.
CI can be built on this foundation: after a change is approved, a build server connects to IBM i, compiles the changed sources in a test library, runs the tests, and reports the result in the code review. It is the same process Java teams have known for years, only with compilation on the IBM i server.
What else has changed around the language
RPG does not live alone. Several tools have grown up around it that change day-to-day work.
- SQL instead of DDS files. Tables, views, and indexes are defined in SQL, and SQL services in the QSYS2 library let you query the system: jobs, objects, journals. More in the article Db2 for i: SQL instead of DDS and a migration plan.
- Open source software in PASE. Node.js, Python, git, and bash run on the same server, so build scripts and CI tools do not need a separate machine.
- Web services. RPG procedures can be exposed as REST through IWS (Integrated Web Services) without writing an HTTP layer. We describe this in the article IBM i and modern applications: integration through REST APIs.
- JSON and XML handling in the language. The DATA-INTO and XML-INTO statements load data into structures, and SQL functions produce JSON from tables.
How to move to modern RPG in an existing team
Nobody rewrites twenty-year-old code in one quarter. The scout rule works: every program you are changing anyway, you leave in better shape.
- Set a standard: new code only in **FREE, descriptive names, no new indicators.
- Move the sources to git and start with code review for new changes.
- Extract repeatable logic (discounts, validations, numbering) into service programs.
- When making changes, replace record operations in new code with SQL queries.
- For key procedures, add tests before you change them.
Tools, including those in RDi, help convert column syntax to free-form. After conversion the code has to be read and tested, because changing the form does not fix the logic. Teams that are just starting with tests will find examples in the article Automated tests for IBM i applications, and you can read about B2Bnetwork engineers' work on such systems in the section What we do.
Questions and answers
Since which IBM i version has fully free-format RPG worked?
Declarations in free format (ctl-opt, dcl-s, dcl-proc) appeared in IBM i 7.1 TR7. Fully free format with the **FREE directive, without column restrictions, came with IBM i 7.2 TR3. Earlier, from V5R1, only calculations could be written in free format, in /free blocks. On newer system versions, all of these options are available right away.
Does SEU still work?
SEU is still in the system and you can open a source in it, but it does not recognize the new RPG syntax, so it reports errors in correct free-form code. For new code, it is better to use VS Code with the Code for IBM i extension or RDi. Both tools compile on the server and show compilation errors next to the code.
Can a Java developer learn RPG?
Yes, and free-form syntax makes it much easier, because it looks like a typical procedural language. Harder than the syntax are the features of the platform: libraries and the library list, activation groups, service programs, packed decimal data types, and working with existing column-based code. A few weeks of working in a pair with an experienced RPG developer on real changes works well.
Can RPG code be kept in git?
Yes. Sources are stored as files in the IFS or in a local repository and compiled with the SRCSTMF parameter of the compiler commands. Code for IBM i and build tools such as IBM's open source Better Object Builder help compile the changed files in the right order. This way RPG changes go through the same code review and CI as the rest of the project.