CFL variable Scope describes the part of the UDF where the variable can be used.
The scope of a CFL variable describes the part of the UDF where the variable can be used. All variables have scope only within the block in which they are defined, and only after they are defined in the block (forward references are not supported). A block is a set of statements contained within:
A CCL UDF defined in a Create Function statement.
Either the THEN or ELSE clauses of an If statement.
Any one of the WHEN clauses or the ELSE clause of a Case statement.
A While statement.
The conditions that appear in the If statement, Case statement, and While statement are in the scope of the surrounding block or function.
The scope of all parameters to any function and all variables that are defined outside of any nested block in the Create Function statement itself is the entire UDF. The scope of all variables that are defined inside any block except the Create Function statement itself is that block and any blocks nested inside that block.
Any variable that is created inside the Create Function statement or any nested block can be used only after it has been created (forward references are not permitted).