In brief
Version control on IBM i comes in four steps: moving source from source physical files (such as QRPGLESRC) to the IFS and git, building the whole application from source automatically, a pipeline that compiles and tests every change in a separate library, and deployment from an approved version instead of copying objects by hand. The RPG and CL compilers accept IFS files, so git works here as in any other project. The hard parts are dependencies between objects and database changes, not the tool itself.
Where the problem comes from
In many companies, source lives in source physical files in libraries, and change history consists of member copies with an “_OLD” suffix and dates in comments. The truth about the system is the compiled objects in production, not the source. When someone applied an emergency fix and did not save the source, the next compile undoes the fix.
So the first step is to establish whether the source matches the objects. For a program, the DSPOBJD command shows the source file, member and change date of the source it was compiled from. Comparing that data with the current members shows programs without source or with source newer than the object. Without this list, the repository will be built from unreliable data. We cover inventory in more detail in the article Documenting a legacy system when its authors are gone.
Step 1: source in the IFS and in git
The CPYTOSTMF command copies a source member to a file in the IFS. When copying, set UTF-8 encoding (CCSID 1208) right away, because git and editors outside IBM i expect it. Git runs on IBM i in the PASE environment as an open source package, but the repository can also live on the developer's machine, with the IFS used only for compiling.
A good repository layout is simple:
- directories by type or by module, for example qrpglesrc, qclsrc, qddssrc, or orders, warehouse;
- extensions that say how to compile: .rpgle, .sqlrpgle, .clle, .pf, .dspf, .sql;
- a separate directory for SQL scripts that change the database;
- a build description file stating which command and parameters create each object.
The first commit is the production state. Before the team starts working in git, compile the entire repository into an empty library and check that all objects are created. That is the only proof that nothing is missing from the repository.
Step 2: building the application from source
The compilers accept source from the IFS: CRTBNDRPG, CRTRPGMOD and CRTSQLRPGI have a SRCSTMF parameter. The problem lies elsewhere, in the order. An RPG program will not compile until the files it uses exist, and a program bound to a service program needs that service program to be built first. The build tool has to know these dependencies. Open projects such as Better Object Builder from IBM and the Code for IBM i extension help you describe build rules and compile only what changed.
Two traps show up in every project:
| Trap | What happens | How to avoid it |
|---|---|---|
| Changing a DDS file format | Programs compiled against the old format fail with a level check error (CPF4131) | Rebuild all programs that use the file, or move to SQL tables with views |
| Changing service program exports | The signature changes, and programs bound to the old one fail | Binder language (STRPGMEXP) with an explicit signature and new procedures added at the end of the list |
Both traps explain why deployment on IBM i is not just “compile the changed file.” The pipeline must know what else to rebuild. Moving from DDS to SQL, which softens the first trap, is described in the article Db2 for i: SQL instead of DDS and a migration plan.
Step 3: a CI pipeline for every change
Once the repository builds itself, CI looks the same as for other technologies. The CI server connects to IBM i over SSH and runs these stages:
| Stage | What happens on IBM i |
|---|---|
| Build | Compile changed objects and those that depend on them into the branch library |
| Test | Unit tests of procedures and comparison of batch run results with a baseline |
| Report | Compile and test errors go back to the code review |
| Release | After approval, a version tag and an object package are created |
The branch library sits in the library list ahead of the production version library, so tests see the new programs plus the remaining old objects. How to build the tests themselves is covered in the article Automated tests for IBM i applications. The general rules of a fast pipeline, for example what to run on every change and what once a day, are the same as for other platforms.
Step 4: deploying to production
Deploying from git means only objects built from a tagged version reach production. There are two approaches: rebuild in production from the same source version, or move the finished objects (for example SAVOBJ to a save file and RSTOBJ). The second gives you certainty that production runs exactly what passed the tests.
A few details decide whether a deployment goes smoothly:
- Programs in use. According to IBM documentation, compiling with REPLACE(*YES) moves the previous version of the program to the QRPLOBJ library, so jobs using it finish their work on the old version.
- Database changes. Tables are not recompiled, because the data would be lost. Changes go in as SQL scripts (ALTER TABLE) in the repository, run once, in a defined order.
- Rollback. Before deployment, save the objects that will be replaced to a save file. Rollback is then a single restore, not a search for the old version.
- Deployment window. Changes to files used by active jobs need exclusive access, so you schedule them outside working hours or between batch runs.
How to introduce it in the team
RPG teams have often worked the same way for many years, so changing tools means changing habits. Starting with one application and one person who guides the others through the first changes works well. The editor can stay the same: RDi and VS Code with Code for IBM i both work with git. The tools around the language are described in the article RPG today: free-form and modern tools.
After a few weeks, the benefits convince the team better than a presentation: history for every line, code review before deployment and an end to questions like “who changed this program and when.” The project on a maintenance team for a public administration system shows an example of a maintenance team working this way, and the section What we do shows the scope of our work on IBM i systems.
Questions and answers
Can DDS files be kept in git too?
Yes. Source for physical, logical, display and printer files is text, so it goes into the repository like any other source. The difference is in deployment: a physical file with data is not recreated by recompiling, but changed in a way that preserves the data. That is why many teams move table definitions to SQL when they adopt git.
What should we do with the change management tool we already have?
First, check whether it supports git. Some commercial tools for IBM i work with a repository and can stay as the deployment layer. If the tool stores source only in its own format, plan the move one application at a time, with a period in which both systems run in parallel.
How do I deploy a program that is currently in use?
Compiling with REPLACE(*YES) moves the old version of the program to the QRPLOBJ library, so running jobs finish on it while new calls use the new one. When you move finished objects instead, check the same behavior in a test environment before the first deployment. Database files are different: changing a table needs exclusive access, so you schedule it for a moment when nobody is using it.
How long does it take to bring git into an existing RPG application?
Moving the source and running the first full build usually fit into a few weeks for one application. Describing dependencies and establishing which source matches production takes longer. The pipeline with tests grows gradually, as the team adds tests for the modules it changes.