Debugging ILE RPG with STRDBG: Breakpoints, EVAL, and WATCH
Most defects are found by reading code carefully. The remainder depend on data, timing, or a deployed object that differs from the source being read. For those, the system debugger shows what the program is actually doing.
Prepare the object
Source-level debugging needs a debug view: DBGVIEW(*SOURCE) on the compile. Two control options make sessions easier: *SRCSTMT aligns statement numbers with source line numbers, and *NODEBUGIO keeps the debugger from stepping through every field an I/O operation moves.
Start safely
STRDBG PGM(...) UPDPROD(*NO) opens the source display. UPDPROD(*NO) prevents production libraries from being updated while the session is active. Set breakpoints, press F12, call the program, and the debugger stops at the first breakpoint reached.
Stop where it matters
BREAK 57 WHEN lineQty >= 500 stops only on the data that shows the defect. WATCH stops at whatever statement changes a given piece of storage β the fastest way to find code that alters a field unexpectedly.
BREAK 57 WHEN lineQty >= 500
EVAL discPct
EVAL priceRec.priceChar : X
WATCH orderTotalLook at the bytes
EVAL displays variables, qualified subfields, and array elements. Adding : X shows storage in hexadecimal, which is how a shifted record layout or invalid packed data becomes obvious.
Batch jobs
A program running in another job is debugged by servicing that job: submit it held, STRSRVJOB against it, STRDBG, set breakpoints, then release the job. RDi provides a graphical front end to the same debugger, including service entry points that stop when a program is called from any job.
Lesson 29's exercise plans a debug session from a defect report and then runs a live STRDBG session on PUB400 against the price update program.
Get the lesson
Lesson 29, βDebugging: STRDBG, Breakpoints, and Watch Variables,β is part of Beginner ILE RPG in IBM i ILE RPG Mastery and is available at ILERPG.com for USD 10. The complete Beginner ILE RPG series β all 18 lessons β is USD 180, or USD 135 with coupon code RPG30, which takes 25% off when you purchase the full series.