To diagnose the bug in the procedure, set breakpoints in the procedure and step through the code, watching the value of variables as the procedure is executed.
Here, you set a breakpoint at the first executable statement in the procedure.
Ensure you are in Debug mode in Sybase Central.
Set a breakpoint at the first executable statement in the procedure.
The statement contains the following text:
Click to the left of this line in the vertical gray bar to set a breakpoint. The breakpoint appears as a red circle. An alternative way to set a breakpoint is to press F9.
Execute the procedure again.
In the left pane, right-click the debug_tutorial procedure and choose Execute from Interactive SQL from the popup menu.
A message box appears, asking if you want to debug the connection from Sybase Central. Click Yes.
Execution of the procedure stops at the breakpoint. A yellow arrow in the source code window indicates the current position, which is at the breakpoint.
The Local tab in the Debugger Details pane displays a list of local variables in the procedure together with their current value and data type. The top_company, top_value, this_value, and this_company variables are all uninitialized and are therefore NULL.
Step through the stored procedure by pressing F11. As you step through the lines of the stored procedure, the value of the variables changes.
Stop stepping through the code when you reach the following line:
IF this_value > top_value THEN
When you are at the
IF statement, this_value is set to 1452 and top_value is still NULL.
Step into one more statement.
Press F11 once more to see which branch the execution takes. The yellow arrow moves directly back to the label statement at the beginning of the loop, which contains the following text:
IF test did not return true. The test failed because a comparison of any value to NULL returns NULL. A value of NULL fails the test and the code inside the
END IF statement is not executed.
At this point, you may realize that the problem is the fact that top_value is not initialized.