Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

Run the debugger_tutorial procedure Next Page

Diagnose the bug

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.

To diagnose the bug
  1. Ensure you are in Debug mode in Sybase Central.

  2. Set a breakpoint at the first executable statement in the procedure.

    The statement contains the following text:

    OPEN cursor_this_customer;

    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.

  3. Execute the procedure again.

    1. In the left pane, right-click the debug_tutorial procedure and choose Execute from Interactive SQL from the popup menu.

    2. 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.

  4. Inspect variables.

    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.

  5. Step through the stored procedure by pressing F11. As you step through the lines of the stored procedure, the value of the variables changes.

  6. 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.

  7. 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:

    customer_loop: loop

    The 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 IF...END IF statement is not executed.

    At this point, you may realize that the problem is the fact that top_value is not initialized.