Even when your program compiles cleanly, you must also test the program by running it. Running a program helps you detect errors in statements with ampersand substitution, errors in logic, and errors in any nested programs.
To test a program by running it, use a full set of test data that is typical of the data that the program processes. To confirm that you test all the features of the program, including error-handling mechanisms, run the program several times, using different data and responses. Use test data that:
Falls within the expected range
Falls outside the expected range
Causes each section of a program to execute
Each time you run the program, confirm that the program executes its statements in the correct sequence and that the output is correct. As an aid in analyzing the execution of your program, you can include
SHOW statements in the program to produce diagnostic or status messages. Then delete the
SHOW statements after your tests are complete.
When you detect or suspect an error in your program or a nested program, you can track down the error by using the debugging techniques that are described in the rest of this section.
When you set the BADLINE option to
YES, additional information is produced, along with any error message when a bad line of code is encountered. When the error occurs, the error message, the name of the program, and the program line that triggered the error are sent to the current outfile. You can edit the specified program to correct the error and then run the original program. See Example 6-4, "Using the BADLINE Option" for an example of using BADLINE.
When your program contains an error in logic, then the program might execute without producing an error message, but it executes the wrong set of statements or produces incorrect results. For example, suppose you write a Boolean expression incorrectly in an
IF statement (for example, you use
NE instead of
EQ). The program executes the statements you specified, but it does so under the wrong conditions.
To find an error in program logic, you often need to see the order in which the statements are being executed. One way you can do this is to create a debugging file and then examine the file to diagnose any problems in your programs by issuing the following DML statements:
Specify that you want each program line to be sent to the debugging file when a line executes by setting the PRGTRACE option to
See Also:The following examples of using a debugging file: