Step 1: Set Up Your Program for Debugging
Before you can debug, your RPG program needs to be ready to spill its secrets. Here’s how to prep:
Compile with Debug Info: When you compile your RPG source (using CRTRPGPGM or CRTBNDRPG), add the DBGVIEW(*SOURCE) or DBGVIEW(*LIST) option. This tells the system to include debugging data. For Free Format RPG, I love *SOURCE because it matches what I see in my editor (like VS Code with the IBM i extension).
Check Your Authority: Make sure you’ve got *CHANGE or *ALL authority to the program object. No one likes a "Permission Denied" buzzkill.
Step 2: Launch the Debugger
IBM i gives you a slick interactive debugger called the STRDBG (Start Debug) command. Here’s how to kick it off:
Start the Debug Session:
Hit Enter, and you’re in! This loads your program into debug mode. You’ll see a screen listing the program(s) you’re debugging.
Set Breakpoints: Breakpoints are your “pause buttons.” Tell the debugger where to stop so you can snoop around. For example:
Call Your Program: Run your program as usual (e.g., CALL MYLIB/MYPGM). When it hits a breakpoint, the debugger takes over, showing you the source code at that exact spot.
Step 3: Step Through and Investigate
Now you’re in the driver’s seat! Use these handy keys to navigate:
While paused, check variable values with:
Step 4: Watch for Common RPG Gotchas
Debugging subfiles or file I/O? Here are some classics to catch:
Step 5: Wrap It Up
Once you’ve nabbed the culprit, exit the debugger with ENDDBG:
Fix your code, recompile, and test again. Rinse and repeat until it’s smooth as a freshly printed green-bar report.
Pro Tips for IBM i Debugging
Debugging RPG on IBM i isn’t just about fixing errors—it’s about understanding your program’s soul. With STRDBG in your toolkit, you can tackle subfile snafus, file flops, or logic loops like a pro. So next time your program throws a tantrum, don’t panic—debug it, fix it, and keep the IBM i humming.
Got a tricky bug you’re wrestling with? Drop a comment below, and let’s squash it together!