Implicit and explicit statement blocks

In an SPL routine, the implicit statement block extends from the end of the CREATE statement to the beginning of the END statement. You can also define an explicit statement block, which starts with a BEGIN statement and ends with an END statement, as the following figure shows.
Figure 1. Explicit statement block.
BEGIN
   DEFINE distance INT;
   LET distance = 2;
END

The explicit statement block allows you to define variables or processing that are valid only within the statement block. For example, you can define or redefine variables, or handle exceptions differently, for just the scope of the explicit statement block.

The SPL function in the following figure has an explicit statement block that redefines a variable defined in the implicit block.
Figure 2. An explicit statement block that redefines a variable defined in the implicit block.
CREATE FUNCTION block_demo()
   RETURNING INT;
      DEFINE distance INT;
   LET distance = 37;
   BEGIN
      DEFINE distance INT;
      LET distance = 2;
   END
   RETURN distance;

END FUNCTION;

In this example, the implicit statement block defines the variable distance and gives it a value of 37. The explicit statement block defines a different variable named distance and gives it a value of 2. However, the RETURN statement returns the value stored in the first distance variable, or 37.