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. Choose Mode » Debug.

  2. In the right pane, double-click Debugger_Tutorial (GROUPO).

  3. In the right pane, locate the following statement:

    OPEN cursor_this_customer;
  4. To add a breakpoint, click the vertical gray area to the left of the statement. The breakpoint appears as a red circle.

  5. In the left pane, right-click Debugger_Tutorial (GROUPO) and choose Execute From Interactive SQL.

    In the Connections tab of Sybase Central, a yellow arrow indicating the breakpoint appears.

  6. In the Debugger Details window, click the Local tab to display 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.

  7. Press F11 to scroll through the procedure. The value of the variables changes when you reach the following line:

    IF this_value > top_value THEN
  8. Press F11 once more to determine which branch the execution takes. The yellow arrow moves back to 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.