Debugging
Is My Program Caught in a Loop?
The other day I was testing a piece of code which I suspected of being stuck in a loop. I was about to take the time to stop the program and set up a debug when I realized I could get this information from the DSPJOB command. When you run DSPJOB (from WRKUSRJOB, WRK-SBSJOB or other means) you are provided with a list of options which includes "Display program stack, if active." This display includes a column which shows the line of code the program is on. This display can be updated with the F5 key. While the program executes too fast to let F5 give you a step by step display, repeated F5's will show you approximately where the program is. It definitely showed me where my loop was happening.
After I knew the code was looping, I could use the "Display open files, if active" option to find out which records were up at the time of the loop. Just this information let me look at my code and figure out what the problem was.
- Kathreen Kruse
Breaking an Active Program Out of a Loop
If a program is caught in an infinite loop and observability has not been removed, it may be possible to break the loop without canceling the program.
Use DSPJOB OPTION(*PGMSTK) to determine where the program is looping. Use STRSRVJOB, then STRDBG and ADDBKP to set a breakpoint within the loop. When the breakpoint is displayed, use CHGPGMVAR to set the conditions necessary for the loop to end.
- Douglas Handy
Easy Program Testing
I always have the library QTEMP as the first library in the library list. When testing an interactive program, I copy the test files to QTEMP. Then, I execute the command STRDBG UPDPROD(*NO) (*NO is the default) before testing the program. This way, I can be sure that I will not update the production files accidentally. I do not need to remember to delete the test files when I'm done since the files in QTEMP will be removed when I sign off.
- Ryoichi Morita
Use SEU to Check Compiler Errors
Use the following technique to find errors in an RPG compile listing. Start SEU, press F15, select option 2 to display the spooled file on a split screen, key in FIND *ERR on the SEU command line of the bottom screen and press Enter. Each error message will be displayed on the bottom of the screen. You can press help for second-level text on each message.
- Christopher Andrle
Protecting Files From Update
There are times when you may wish to run a program that writes records to a file, but for test purposes, you wish to prevent this from happening. You could recompile your test program, commenting out the write or update operations, and changing the file specs so the compiler doesn't give you an error message. However, a much better and easier approach is to use the INHWRT(*YES) parameter on the OVRDBF command. You should execute this command for each file you wish to inhibit at the beginning of your jobstream. Be careful not to misspell the file name. You will not get an error message if you do, but the file will not be overridden. (To check that the override has occurred, use the DSPOVR command.) After the override command is executed successfully, the program will act just as before, but no data will be written.
- Jon Vote
LATEST COMMENTS
MC Press Online