<< Label >> statement

Use the <<label>> statement of SPL to declare a statement label or a loop label.

  • A statement label is an SQL identifier, delimited by double angle-brackets, immediately preceding a statement within a statement block to which the GOTO statement of SPL can transfer control of program execution.
  • A loop label is an SQL identifier, delimited by double angle-brackets, immediately preceding a loop statement of SPL. The same label, without double angle-bracket delimiters, can follow the END LOOP keywords, or END FOR keywords, or END WHILE keywords that terminate the labeled loop. The EXIT label statement can pass control of program execution to whatever statement immediately follows the undelimited loop label.
Note that label is not a keyword of the <<label>> statement, but is a placeholder for some specific user-defined identifier of the statement label or loop label that the <<label>> statement declares.

Syntax

<<label>>
Element Description Restrictions Syntax
label Name that you declare here for a statement label or for a loop label Must be unique among the identifiers of statement labels and of loop labels within the SPL routine Identifier

Usage

You can use the <<Label>> statement in two ways:
  • To declare a statement label before an executable statement to which the GOTO statement of SPL can transfer control of execution. The SPL statement that immediately follows the statement label declaration is called a labeled statement.
  • To declare a loop label immediately before a LOOP, FOR, or WHILE statement of SPL. The LOOP, FOR, or WHILE statement that immediately follows the loop label declaration is called a labeled loop.

The EXIT label or EXIT label WHEN (condition) statement can exit from the labeled loop, passing control of execution to the statement immediately following an END LOOP label statement. The label specified in the EXIT statement can match the label identifier of the labeled loop of the EXIT statement, or if loops are nested, this label can match the label of an outer labeled loop. In either case, the EXIT label statement passes control to a statement that follows an END LOOP label statement that specifies the same loop label. This EXIT label behavior differs from that of the GOTO label statement, which passes control to the statement that follows the declaration of the specified statement label.

The following restrictions apply to labels in SPL routines:
  • The name of a statement label must be within the scope of reference of the GOTO statement.
  • The GOTO option of the WHENEVER statement of SQL cannot reference an SPL statement label, because the WHENEVER statement is valid only in ESQL/C applications.
  • The GOTO statement of SPL cannot reference a loop label.
  • The GOTO statement cannot reference a statement label within an ON EXCEPTION statement block.
  • A statement label cannot be declared within an ON EXCEPTION statement block.
  • The label name must be unique among statement labels and loop labels within the SPL routine.