Nested routine invocations
In the context of routines, nesting refers to the situation where one routine invokes another.
That is to say, the SQL issued by one routine can reference another routine, which could issue SQL that again references another routine, and so on. If the series of routines that is referenced contains a routine that was previously referenced this is said to be a recursive nesting situation.
You can use nesting and recursion in your routines under the following
restrictions:
- 64 levels of nesting
- You can nest routine invocations up to 64 levels deep. Consider a scenario in which routine A calls routine B, and routine B calls routine C. In this example, the execution of routine C is at nesting level 3. A further 61 levels of nesting are possible.
- Other restrictions
- A routine cannot call a target routine that is cataloged with
a higher SQL data access level. For example, a UDF created with the
CONTAINS SQL clause can call stored procedures created with either
the CONTAINS SQL clause or the NO SQL clause. However, this routine
cannot call stored procedures created with either the READS SQL DATA
clause or the MODIFIES SQL DATA clause (SQLCODE -577, SQLSTATE 38002).
This is because the invoker's SQL level does not allow any read or
modify operations to occur (this is inherited by the routine being
invoked).
Another limitation when nesting routines is that access to tables is restricted to prevent conflicting read and write operations between routines.