Part 3: Build Real Things
Part 2 taught the language. Part 3 puts it to work.
Each tutorial here builds a small, realistic RPG program on the PRODUCT, SUPPLIER, and REORDCND tables you created in Part 1. The programs aren’t toys — they’re the shape of real work you’d do in an IBM i shop: look things up, iterate through records, calculate, write results back, handle errors, test your work.
The tutorials are progressive. Later ones assume you’ve internalized the earlier ones. Work through them in order the first time. Come back to individual ones as reference after that.
The twelve tutorials
Reading data
- Product Lookup and Price Calculation — your first program that takes parameters, reads the database, applies business logic
- Reading Records with CHAIN — native random-access I/O, and when to use it instead of SQL
- Sequential Reading with SETLL and READ — walking a file one record at a time
- Multi-Row Queries with SQL Cursors — the modern equivalent, plus the
extnameDS trick
Building real programs
- Building Reusable Logic with Procedures — structuring code as main + helpers
- Service Programs — packaging procedures for reuse across programs
- Batch Reorder Report — The Capstone — everything so far, applied to a real batch job
Operational quality
- Error Handling with MONITOR — graceful handling of bad data and SQL failures
- Date Math in Practice — a stale-price audit program
- CL — The Glue Language — wrappers, parameter passing, job scheduling
Capstone and confidence
- Roman Numeral Converter — A Procedures Capstone — a pure-algorithm exercise in procedural composition
- Writing Tests with RPGUnit — automated testing for the programs you’ve built
Tutorial format
Every tutorial in Part 3 follows the same structure:
- What you’ll build — one paragraph describing the program and its inputs/outputs
- What you’ll learn — the concepts this tutorial anchors
- The program — the full source code, ready to compile
- Walkthrough — section-by-section explanation of what the code does and why
- Compile and run — how to get it running on your PUB400 account
- Try this — extensions to deepen your understanding
- What’s next — link to the next tutorial
Before you start
- Part 1 complete — you’re connected to PUB400 and your practice tables exist
- Part 2 read through at least Chapter 5 — the tutorials here assume you can read embedded SQL
- Your library name from Part 1 (you’ll substitute it in a few places)
Ready? Start with Tutorial 1: Product Lookup and Price Calculation.
Many programs in Part 3 are adapted from a K3S internal training curriculum written by Mike Scampini and Lauren Brakke. Their originals have been re-worked for the PUB400 environment and the public tutorial schema, but the teaching shape of the code is theirs.
Table of contents
- 1. Product Lookup and Price Calculation
- 2. Reading Records with CHAIN
- 3. Sequential Reading with SETLL and READ
- 4. Multi-Row Queries with SQL Cursors
- 5. Building Reusable Logic with Procedures
- 6. Service Programs
- 7. Batch Reorder Report — The Capstone
- 8. Error Handling with MONITOR
- 9. Date Math in Practice
- 10. CL — The Glue Language
- 11. Roman Numeral Converter — A Procedures Capstone
- 12. Writing Tests with RPGUnit