SQL$HELP_OLD72.HLB  —  WHENEVER
    Specifies the execution path a host language program will take
    when any embedded SQL statement results in one of these following
    exception conditions:

    o  Row not found

    o  An error condition

    o  A warning condition

    For these conditions, the WHENEVER statement specifies that
    the program continue execution or branch to another part of the
    program.

1  –  Environment

    You can issue the WHENEVER statement only in host language
    programs.

2  –  Format

  WHENEVER  --+-> NOT FOUND --+----+
              +-> SQLERROR ---+    |
              +-> SQLWARNING -+    |
    +------------------------------+
    +-+-> CONTINUE ----------------------------------+->
      +-> GOTO --+-+-+-------+-> <host-label-name> --+
      +-> GO TO -+ | +-> : --+                       |
                   +-----------> <host-label-number> +

3  –  Arguments

3.1  –  CONTINUE

    Specifies that the program continue execution with the next
    sequential statement following the statement that generated an
    error.

3.2  –  GOTO

    Syntax options:

    host-label-name | host-label-number

    Specifies that the program branch to the statement identified
    by the host label. The form of the host label depends on the
    host language. You can use a colon (:)  before a host label
    represented by a name, but not before a host label represented
    by a number.

3.3  –  NOT_FOUND

    Indicates the exception condition returned when SQL processes all
    the rows of a result table:

    o  When a cursor referred to in a FETCH, UPDATE, or DELETE
       statement is positioned after the last row

    o  When a query specifies an empty result table

    This is the same condition identified by a value of 100 in the
    SQLCODE variable, the value of '02000' in the SQLSTATE variable,
    and by the RDB$_STREAM_EOF error.

3.4  –  SQLERROR

    Indicates any error condition. For the SQLERROR argument of
    the WHENEVER statement, SQL defines an error condition as any
    condition that returns a negative value to SQLCODE.

3.5  –  SQLWARNING

    Indicates any warning condition.

4  –  Example

    Example 1: Using WHENEVER statements in a PL/I program

    /* When an SQL statement results in
    an RDB$_STREAM_EOF error, the
    program branches to LABEL_NOT_FOUND: */
    EXEC SQL WHENEVER NOT FOUND GOTO LABEL_NOT_FOUND;

    /* When an SQL statement results in a
    warning severity error condition, the
    program branches to LABEL_ERROR: */
    EXEC SQL WHENEVER SQLWARNING GOTO LABEL_ERROR;

    /* When an SQL statement results in
    an error severity exception condition, the
    program branches to LABEL_ERROR: */
    EXEC SQL WHENEVER SQLERROR GOTO LABEL_ERROR;
Close Help