Trying to find a reason to use ADDTRC

Over years of debugging you've undoubtedly heard the mention of 'trace' many times. However, with RPGLE programmers it seems this feature is very seldom used. Why? Maybe because the source debugger does such a good job of setting (conditional) breakpoints, displaying variable values, and stepping through a program (visually) that a tool that prints or displays statement numbers and values is rarely helpful (and often redundant). Add the fact that ADDTRC is not valid for bound programs and the value of this command is further restricted.

However, ADDTRC can be thought of more as a supplement to your tool kit rather than an alternative. Like ADDBKP adding a trace is only allowed while in debug mode. STRDBG has a couple of trace parameters; optionally stopping the trace or wrapping the results after a specified number of statements. Enter the ADDTRC command at a similar time as you would add a breakpoint. After a breakpoint is reached, or after the program completes, the command DSPTRCDTA can be used to display or print the results, which are the statement numbers executed and, optionally, variables and their values when those statements ran.

The ADDTRC allows for single statements, all statements, or up to five ranges of statements to be traced. Also you can view variables that were changed during the program if you specified any variables on the ADDTRC and specified OUTVAR(*CHG). A trace can be used to determine exactly what statements and in what order they are actually executing (ie. the program's path).

For example, you want to trace from high level language statements 1000 to 1200 and you want to know what is in the order number field 'OrdNum'.

addtrc stmt((1000 1200)) pgmvar(OrdNum)

If you only want to see statements when the order number has changed;

addtrc stmt((1000 1200)) pgmvar(OrdNum) outvar(*chg)

Next, dsptrcdta to see what actually happened to the variable and at which statement. Whenever enddbg is issued the traces are removed from the program. Once the trace session is complete and you are finished with your analysis do clrtrcdta to remove the trace results.

Conclusion: Adding a trace can still be helpful for ILE programs but not bound programs. The value the command adds, while limited, seems to be in assisting the programmer in determining the flow a program is taking, and finding where a variable is actually getting changed.