TexAS400 Tutorial


Debugging RPG ILE with the iSeries / AS400 Debugger STRDBG

The AS/400 has a built in debugging tool, though very powerful, it is not completely intuitive. Sometimes you may find yourself in need of a procedure that can help you locate program errors that you cannot visually find by looking at your program. RPG-ILE's program debugger can be very useful in these situations. It allows you to trace a program as it is executing, stepping through a program a statement at a time, or stopping at "breakpoints" that you designate so you can see the values of fields at that point of execution. Follow the steps below to start the "debugging" mode for your programs.

First, you must compile the program in an appropriate mode. Do this from PDM by keying a 14 next the program source and hitting F4.

Your screen should look like this:


Create Bound RPG Program (CRTBNDRPG)                
                                                                         
Type choices, press Enter.                                               
                                                                         
Program  . . . . . . . . . . . . > LXR001        Name, *CTLSPEC          
  Library  . . . . . . . . . . . >   T40         Name, *CURLIB           
Source file  . . . . . . . . . . > QRPGLESRC     Name, QRPGLESRC         
  Library  . . . . . . . . . . . >   T40         Name, *LIBL, *CURLIB    
Source member  . . . . . . . . . > LXR001        Name, *PGM              
Generation severity level  . . .   10            0-20                    
Text 'description' . . . . . . .   *SRCMBRTXT                            
                                                                         
Default activation group . . . .   *YES          *YES, *NO               
Now, hit F10 to get more options. Key in *LIST as the value for "Debugging View".

The screen should look like:


                     Create Bound RPG Program (CRTBNDRPG)                 
                                                                          
Type choices, press Enter.                                                
                                                                          
Program  . . . . . . . . . . . . > LXR001        Name, *CTLSPEC           
  Library  . . . . . . . . . . . >   T40         Name, *CURLIB            
Source file  . . . . . . . . . . > QRPGLESRC     Name, QRPGLESRC          
  Library  . . . . . . . . . . . >   T40         Name, *LIBL, *CURLIB     
Source member  . . . . . . . . . > LXR001        Name, *PGM               
Generation severity level  . . .   10            0-20                     
Text 'description' . . . . . . .   *SRCMBRTXT                             
                                                                          
Default activation group . . . .   *YES          *YES, *NO                
                                                                          
                           Additional Parameters                          
                                                                          
Compiler options . . . . . . . .                 *XREF, *NOXREF, *GEN...  
               + for more values                                          
Debugging views  . . . . . . . .   *LIST         *STMT, *SOURCE, *LIST... 
Output . . . . . . . . . . . . .   *PRINT        *PRINT, *NONE            
Now ENTER to compile your program. If this program calls other programs, you may want to compile them in debug mode also.

Now it gets a little tricky. Start the debugging mode with the "Start Debug" for the program you want to debug. In this case, the program is LXR001 so the command to use is STRDBG LXR001. Key in STRDBG LXR001 and hit F14:


                              Start Debug (STRDBG)                      
                                                                        
 Type choices, press Enter.                                             
                                                                        
 Program  . . . . . . . . . . . . > LXR001        Name, *NONE           
   Library  . . . . . . . . . . .     *LIBL       Name, *LIBL, *CURLIB  
                + for more values                                       
                                      *LIBL                             
 Default program  . . . . . . . .   *PGM          Name, *PGM, *NONE     
 Maximum trace statements . . . .   200           Number                
 Trace full . . . . . . . . . . .   *STOPTRC      *STOPTRC, *WRAP       
 Update production files  . . . .   *NO           *NO, *YES             
 OPM source level debug . . . . .   *NO           *NO, *YES             
 Service program  . . . . . . . .   *NONE         Name, *NONE           
   Library  . . . . . . . . . . .                 Name, *LIBL, *CURLIB  
                + for more values                                       
                                                                        
If your program updates or writes data to a file in a library that is defined as *PROD, you must change the "Update production files" option to *YES. Then, hit ENTER.

The debugger now displays the source code of the program. You MUST define a breakpoint where the debugger will actually start debugging. The easiest thing to do is to page down to the first executable statement of the program. Put the cursor on that line of source code and hit F6 to define that line as a breakpoint.

Now, hit F3 and you will return to the PDM menu.

Your session is now in "debug" mode. It will stay in "debug" mode until you end debug mode with the command ENDDBG.

Finally, it is time to start running your program. Call the program from the command line. In this case: CALL LXR001

The program will start running. The debug feature will display a listing of the program. The display is showing that the breakpoint is about to execute. You can scroll up or down, position the cursor on any field and hit F11. The debugger will display the value of the field.

Now hit F10 repeatedly to step through the source code. The line of code that is about to execute will be highlighted.

Note that the debugger has the annoying habit of stepping through every field in each file that is read or updated. To prevent this, add a "header" record as the first line of code in the program. "Header" records are not required and not usually used. Use an "H" as the record type with a value of "option(*nodebugio). That is, add this line to the beginning of your program:

H OPTION(*NODEBUGIO)

When you are finished debuggin, key ENDDBG to turn off the debugger.

To summarize:

1)   Add this line to the beginning of your program:    H OPTION(*NODEBUGIO)

2)   Compile the program with Debug View set to *LIST

3)   Start the debugger with the command:    STRDBG pgmname (Update Production files *YES)

4)   Put cursor on the first line that you want to see and hit F6. Exit with F3.

5)   Call your program:   CALL pgmname

6)   Use F10 to step through the program. Use F11 to see values.

7)   If you wish, set additional breakpoints and use F12 to run until the next breakpoint.

 

 

Back to Table of Contents   |   Main Page