Debugging CL programs in AS400 (IBM i) involves a combination of techniques and tools. Here's a breakdown of the process:
1. Preparation:
DBGVIEW(*SOURCE)
or DBGVIEW(*ALL)
parameter on the CRTCLPGM
or CRTBNDCL
command.2. Starting the Debugger:
STRDBG
command to start the debugger. Specify the program you want to debug:STRDBG PGM(library/program-name)
OPMSRC(*YES)
on the STRDBG
command.UPDPROD
parameter controls whether you can make changes to production files during debugging. It's generally recommended to keep this set to *NO
to avoid unintentional modifications to live data.3. Debugging Commands:
Once the debugger starts, you'll be presented with a display showing your CL program's source code. You can use various debug commands to control the debugging session:
BREAK
: Set breakpoints at specific lines in your code to pause execution.CLEAR
: Remove breakpoints.F6 (Add/Clear Breakpoint)
: Use this function key to toggle breakpoints on the displayed source code.STEP
or F10
: Execute the next statement.STEP INTO
or F22
: Step into a called program or subroutine.EVAL
: Display or change the value of a variable.ATTR
: Display the attributes (type, length) of a variable.DISPLAY
: Display a different source module.FIND
: Search for a string or line number in the source code.UP
, DOWN
, LEFT
, RIGHT
: Scroll through the source code.TOP
, BOTTOM
: Go to the beginning or end of the source code.HELP
: Display help information about debug commands.SET
: Change debugging options.WATCH
: Monitor the value of a variable or expression.4. Debugging Process:
STEP
, STEP INTO
) to execute your CL program line by line. This allows you to observe the program's flow and identify any logical errors.EVAL
command to examine the values of variables at different points in your program. This helps you understand how data is being processed and identify any incorrect values.EVAL
to evaluate expressions and see the results. This can be useful for debugging complex logic.5. Ending the Debugger:
ENDDBG
command to end the debugging session.Tips for Effective Debugging: