I could write this in RPG in no time.
That was what I thought as I tried to make a CL program write to a database instead. This was an AS/400 task I wrote about in October 2024.
CL stands for Control Language. It lets you organise a sequence of operations, use variables, and branch according to conditions.
But when it comes to reading and writing database records, RPG feels much more natural to me. Read the data, process it, write it out. Familiar work.
Even so, I wanted to avoid adding another RPG program for this task.
Looking back at my blog entry, I was concerned about the work that came with creating another program object. Documentation, in particular.
One more program meant documentation for that program too. The time needed to write the code was only part of the decision.
Of course, figuring out how to do it in CL took some effort of its own. (Laughs.)
Reading was fairly straightforward.
Declare the database file with DCLF, then read its records in sequence with RCVF. Use MONMSG to watch for the message indicating the end of the file.
Then came the writing.
There was a command called SNDF. Its name looked promising. But it sends data to a display; it cannot write to a database file.
I had a way to read records, but the corresponding way to write them was not falling into place.
So I used SQL.
I built an SQL statement beginning with INSERT INTO to add the data, then executed it with the RUNSQL command.
Calling SQL from CL let me handle the write without adding a separate RPG program to do it.
My blog entry ended on a satisfied note: it had been a little troublesome, but I had avoided adding another object, so that was good enough.
The finished code is not included in that old post. What remains is a short account of where I got stuck and how I got past it.
Reading it again, the concern about documentation beyond the program itself feels very familiar. That is part of the work too.
An RPG enthusiast, working out how to avoid writing one more RPG program.
Some days are like that. (Laughs.)
A note added today
This article was adapted from my 4 October 2024 blog post, “AS/400のCLでデータベースを操るのは難儀やな” (“Working with a Database in AS/400 CL Is Awkward”). The original does not identify the operating system version used at the time.
The IBM i 7.4 documentation checked for this article describes reading database files with RCVF and executing INSERT statements with RUNSQL. The account of avoiding an additional RPG program comes from my contemporary blog entry.
References, checked on 19 October 2026:
- IBM: Receive File (RCVF)
- IBM: Send File (SNDF) — the display-only restriction is also explicit in this command reference.
- IBM: Using the RUNSQL CL command