informix
Informix Guide to SQL: Tutorial
Creating and Using SPL Routines

Debugging an SPL Routine

After you successfully create and run an SPL routine, you can encounter logic errors. If the routine has logic errors, use the TRACE statement to help find them. You can trace the values of the following items:

To generate a listing of traced values, first use the SQL statement SET DEBUG FILE to name the file that is to contain the traced output. When you create the SPL routine, include a TRACE statement.

The following methods specify the form of TRACE output.

Statement Action
TRACE ON Traces all statements except SQL statements. Prints the contents of variables before they are used. Traces routine calls and returned values.
TRACE PROCEDURE Traces only the routine calls and returned values.
TRACE expression Prints a literal or an expression. If necessary, the value of the expression is calculated before it is sent to the file.

Figure 10-107 demonstrates how you can use the TRACE statement to monitor how an SPL function executes.

Figure 10-107

With the TRACE ON statement, each time you execute the traced routine, entries are added to the file you specified in the SET DEBUG FILE statement. To see the debug entries, view the output file with any text editor.

The following list contains some of the output that the function in Figure 10-107 generates. Next to each traced statement is an explanation of its contents.

Statement Action
TRACE ON Echoes TRACE ON statement.
TRACE Foreach starts Traces expression, in this case, the literal string Foreach starts.
start select cursor Provides notification that a cursor is opened to handle a FOREACH loop.
select cursor iteration Provides notification of the start of each iteration of the select cursor.
expression: (+lcount, 1) Evaluates the encountered expression, (lcount+1), to 2.
let lcount = 2 Echoes each LET statement with the value.


Informix Guide to SQL: Tutorial, Version 9.2
Copyright © 1999, Informix Software, Inc. All rights reserved