RPG development: from opcodes to procedures
Plain-English notes, safe code skeletons, IBM i commands, and a checkpoint you can use before opening the deeper question bank.
- Read an RPG program as declarations, calculations, I/O, and procedure calls.
- Translate a fixed-format operation into modern free-form RPG deliberately.
- Explain parameter contracts, indicators, data structures, and test seams.
Learning notes
Read RPG in the order the compiler sees it
Begin with control options and file or data declarations. Then identify entry parameters, procedures, and the main business operation. Finally trace I/O and status checks. This order is more reliable than starting at the first calculation line and guessing what every field means.
RPG opcodes express intent such as CHAIN, SETLL, READE, UPDATE, CALL, and EXSR. Built-in functions such as %FOUND, %EOF, %TRIM, and %SUBST report state or transform values. Say what state each operation changes before explaining syntax.
- Declare files, prototypes, and data
- Receive parameters and validate input
- Read or query the required records
- Apply business rules in a procedure
- Write results and return a clear status
Fixed format and fully free format carry the same intent
Fixed-format RPG is common in maintenance code because its columns carry meaning. Fully free RPG makes declarations and operations easier to review in new work. The important interview skill is preserving behavior while making status handling and data scope clearer.
Keep examples small enough to test. A keyed read should show the found check, and a write should show the validation and error path.
One behavior, two source styles
Fixed format
C orderId CHAIN OrderRec C IF %FOUND(Orders) C EVAL status = 'READY' C UPDATE OrderRec C ENDIF
Fully free
**FREE chain orderId OrderRec; if %found(Orders); status = 'READY'; update OrderRec; endif;
Use procedures as contracts
A procedure should have a clear purpose, typed parameters, and a predictable result. Put conversion, validation, and database access behind small procedures so a test can exercise them without running an entire display program.
For subfiles and display files, keep screen flow separate from data retrieval. The UI procedure can request a page of rows; a data procedure can own the key range and status rules.
Procedure skeleton
dcl-pr buildGreeting varchar(80);
customerId packed(9:0) const;
end-pr;
dcl-proc buildGreeting;
dcl-pi *n varchar(80);
customerId packed(9:0) const;
end-pi;
// validate, read, and return one explicit result
end-proc;Open the detailed question chapters
- RPG, RPGLE & RPG IV · 8 questions
- RPG opcodes & indicators · 8 questions
- RPG procedures & data structures · 6 questions
- Display files, subfiles & printing · 9 questions
- Coding lab: RPGLE and CL from fixed to free form · 44 questions
Practice checkpoint
Answer all five, then review the explanations. The interactive site stores your completed learning checkpoints in this browser.
- 1. What does SQLRPGLE commonly identify?
- A job description
- Only fixed-format RPG II
- A database schema
- RPG source with embedded SQL
- 2. Which type choice is usually suitable for fixed-scale money?
- Packed decimal with explicit precision and scale
- An arbitrary text buffer
- A job number
- A pointer
- 3. Does free-form conversion automatically remove global state?
- Yes, always
- No
- Only on Power hardware
- Only in QTEMP
- 4. Which BIF checks whether CHAIN found a record?
- %TRIM
- %CHAR
- %FOUND
- %LEN
- 5. A program fails only on its second call in one job. Investigate:
- Only source indentation
- Only the terminal emulator
- Whether the file has a long name
- Retained state and cleanup
Show answer key and explanations
1. D — RPG source with embedded SQL It signals the SQL-aware RPG build path.
2. A — Packed decimal with explicit precision and scale Decimal arithmetic supports an explicit business rounding and range policy.
3. B — No Source layout and program architecture are separate concerns.
4. C — %FOUND Check the relevant file status immediately after the read.
5. D — Retained state and cleanup RETURN and runtime lifecycles can preserve state across calls.
IBM documentation for this path
- IBM: ILE RPG reference (7.6)
- IBM Redbooks: Modern RPG
- IBM Docs: RPG file operations
- IBM: Keys for file operations
- IBM: Service program signature
- IBM: Work management (7.5)
- IBM: SFLSIZ keyword
- IBM: Subfile record selection example
- IBM: SFLNXTCHG behavior
- IBM Docs: RPG IV Reference
- IBM Docs: RPG built-in functions
- IBM Docs: RPG procedures and prototypes
- IBM Docs: Embedded SQL programming
- IBM Docs: CL programming
- IBM Docs: Monitor Message (MONMSG)
- IBM Docs: Submit Job (SBMJOB)
- IBM Docs: Override with Database File (OVRDBF)
- IBM Docs: Data queues