The solution to this lies in using the "local environment object" (.local). If you are unfamiliar with this, then it can be seen as a way of creating variables which are available across all of the rexx routines that are running under the same invocation of rexx. This means all subroutines and functions called from your main program. If you execute external code by invoking a new copy of rexx then the .local object will not cross this boundary.
The following pages show the exact version of the debug routines that I'm currently using.