Skip to content

Documenting a legacy system when its authors are gone

B2Bnetwork team · · 7 min

IBM i, RPG and mainframe

In brief

The documentation of a legacy system without its authors is reconstructed from the system itself and from the people who use it. First an inventory: which programs, files, and jobs exist and which are really used. Then a dependency map from system tools (on IBM i, for example DSPPGMREF and DSPDBR), a description of processes from conversations with users, and tests that capture current behavior. Documentation is written starting with the processes most important to the company, not with the first program in the library.

Where to start: an inventory

The first question is: what is in the system at all and what is used. In old systems, half of the objects are often copies, trial versions, and programs nobody has run for years.

On IBM i, object statistics are available through an SQL query. The QSYS2.OBJECT_STATISTICS function returns, among other things, the last-used date and the number of days of use for each object:

SELECT objname, objattribute, objtext,
       last_used_timestamp, days_used_count
  FROM TABLE(QSYS2.OBJECT_STATISTICS('APPLIB', '*PGM')) AS o
 ORDER BY last_used_timestamp NULLS FIRST;

The result gives a first split: programs used daily, programs run once a month or once a year (year-end close, recalculations), and unused programs. The last group does not need documentation but a decision on archiving, after making sure they are not needed in rare processes. On a mainframe, a similar role is played by scheduler reports and run statistics.

A dependency map from system tools

Code does not lie, but you have to know where to look. System tools show dependencies without reading every program.

QuestionTool on IBM i
Which files and programs does a program use?DSPPGMREF with output to a file
Which logical files and views are based on a file?DSPDBR
What fields does a file have and what do they mean?DSPFFD, the QSYS2.SYSCOLUMNS catalog with column descriptions
Which batch jobs run a program?The job scheduler, CL programs, job logs

The DSPPGMREF command writes references to a file that can be queried with SQL:

DSPPGMREF PGM(APPLIB/*ALL) OUTPUT(*OUTFILE) OUTFILE(QTEMP/PGMREFS)

The result contains the program name and the name of the object it refers to (the WHPNAM and WHFNAM fields). One query with GROUP BY shows which files are used by the most programs, meaning where a change will be riskiest. From this a map is built: processes, programs, files, and jobs. It is enough to draw it for the key processes, not for the whole system.

Processes from conversations with users

Tools show how programs are connected but not why. Users know that: sales, accounting, the warehouse.

A conversation with a user at the screen gives more than a survey. Ask them to show how they perform a typical task, and write down:

  • which screens and options they choose and in what order,
  • what values they enter and where they get them from,
  • what they do when something does not match, and what workarounds they know,
  • when in the year the task looks different, for example at year-end close.

Workarounds are especially valuable. Manual corrections that accounting makes every month are often a trace of a rule that someone once added to the code, or forgot to add. Without them, the documentation describes a system that does not exist.

What to record about each process

Documentation reconstructed without the authors makes sense when every process is described using the same template. Then a new person knows where to look, and gaps are immediately visible. One page per process is enough:

ElementExample for invoicing
Purpose and business ownerIssuing invoices for warehouse dispatches, the sales department
Trigger and scheduleDaily at 22:00 after dispatches close, manually on demand
Programs and jobsA list from the dependency map, in call order
Input and output filesDispatches, price lists, discounts; invoices, line items, a file for accounting
Business rulesGroup discounts, rounding, currencies, customer exceptions
Known workaroundsManual correction of consolidated invoices at month end
What to do on errorWhich step to resume from, whom to notify

It is worth keeping a field dictionary separately, because the same abbreviations appear in many files. A field named STKOD can mean customer status in one file and a VAT rate in another. Column descriptions from DDS (the texts and headings of fields) are visible in the QSYS2.SYSCOLUMNS catalog and give a good starting point, if the authors ever filled them in.

Tests as documentation that does not age

A description in a document goes stale at the first code change. A test that fails when behavior changes never goes stale. That is why reconstructing documentation is worth combining with building regression tests.

The simplest test is a data comparison: a prepared input set, running the process, comparing the result with a saved baseline. Each test case describes a rule: “a customer from group B gets a discount on an order above the threshold.” A collection of such cases is a specification that can be run. We describe the technique in the article Automated tests for IBM i applications.

Where to keep documentation and how AI helps

Documentation makes sense only if people find it and correct it. It is best kept next to the code, in the repository, in simple text files: a process description, a program map, a field dictionary, decisions, and known workarounds. Then a code change and a change to the description go through review together.

AI assistants speed up reading code: they summarize a program, describe the data flow, and suggest comments. With old RPG and COBOL this is a real time saver, but the output has to be checked, because a model does not know the business context and can confidently give a wrong explanation. A good practice: AI writes a draft, and an engineer checks it against the code, the tests, and the user. More on working with assistants in the article AI assistants in programming: what they change in code review and testing.

An example of a team working on a mature system, where documentation and maintenance go together, is shown in the scenario a maintenance team for an administration's domain system. We describe the next steps after reconstructing the knowledge in the article IBM i modernization: refactoring, APIs, or migration.

Questions and answers

Where do you start documenting a system nobody knows?

With an inventory: a list of programs, files, and jobs with their last-used dates. On IBM i, a query to QSYS2.OBJECT_STATISTICS gives it. Then pick two or three processes most important to the company, for example invoicing and month-end close, and for them build a dependency map, a description from conversations with users, and tests. The rest of the system can wait.

How long does it take to reconstruct the documentation?

It depends on the size of the system and the number of processes, so there is no single number. An inventory from system tools usually takes days, not weeks. Describing one process with a map, conversations, and tests is a few weeks of work. The whole system is not documented at once: documentation grows with successive changes, and the processes with the greatest risk take priority.

Can you delete programs that nobody uses?

You can, but carefully. The last-used date shows whether an object has been run, but it does not cover processes rarer than the statistics period, for example a year-end close or recalculations after a change in regulations. It is safer to first move such programs to an archive library, save a copy, and delete them after a full annual cycle with no reports.

Can an AI assistant write the documentation for the team?

It can prepare a draft: a program description, data flow, comments on the code. This speeds up the work, especially with long RPG and COBOL programs. The draft has to be checked against the code, tests, and users, though, because a model does not know the business context or dependencies with other programs. Unverified documentation can be more dangerous than none.

What it looks like in a project

Developing a system on IBM i or mainframe? Talk to an RPG engineer.

Let's talk

Read more: IBM i, RPG and mainframe