Finding SQR Errors | KEVIN RESCHENBERG 03-22-2006 |
SQR generally gives good error messages for both
syntax and run-time errors, but it can be
surprisingly difficult at times to find the
corresponding section of code or determine how
to correct an error. Today's post will
be a quick list of suggestions for dealing with
these issues.
"Error on line __" messages can be a little
misleading, because SQR sometimes miscounts
the lines. It can point to a line that's
correct but near the error. Look for the line,
but if it appears to be OK, look a few lines
above or below that line.
It's not quite that easy when the error occurs
in an #INCLUDEd file (an .SQC file). SQR will
still report "error on line 123," but will not
tell you which file's line 123 has the error.
You could start opening up SQCs and searching,
but a much easier way is to use a tool such
as SP Debugger,
which will point to the error. It uses the line
number reported by SQR. Once again, that could
be a few lines off, but you will be able to see
immediately where the error is and in which
file it occurs.
SQL errors often produce an "error in cursor __"
message. How do you know which SQL statement
corresponds to the cursor number listed? The
best way to determine this is to turn on the
SQL trace flag, -S. Specify -S in SQRW, your
batch command line, the command line
option in the process definition, or your
SQR debugger. However, also look for another
error message immediately following the cursor
message. It should point to the start of the
SQL statement (the BEGIN-SELECT or BEGIN-SQL
line).
SQL errors can be handled using the ON-ERROR
clause on the BEGIN-SELECT or BEGIN-SQL statement.
But if all of the ON-ERRORs in your program
point to the same procedure, it can be difficult
to find the source of the problem. Two solutions
are commonly used. You could fill a global
variable with information about the SQL statement
to be executed, or you could pass a parameter
using the ON-ERROR. The error-handling procedure
can then report this information.
If you need to do several SQL statements, you
can enclose all of them within one BEGIN-SQL
section. However, this can make it difficult to
find the source of an error. I prefer to place
each statement within its own BEGIN-SQL block.
This way, if one of the updates generates an
error, it is easier to find the corresponding
statement in the program because SQR will
point to that block.
If you don't understand an error message and the
SQR manual doesn't help, Google it. Sometimes
you can find a quick solution through my other
site, sqr-info.com. Check
out the Specific SQR Topics
page.
|