Hi;
this answer uses only user RPL techniques, O.K.? If there are better solutions with SYS RPL or Assembler, I do not know them.
The way I know to achieve this is by "going to" the directory at the beginning of the program and using an UPDIR at the end of it to get back to the original directory, provided that the variables' directory is a subdirectory of the program's directory itself. (is it clear?).
Say you face the following tree and [prog1] is your main program:
HOME (in other systems it may be called ROOT)
PRGM1 [prog1] [prog2] ... [progn]
VAR1 [v01] [v02] [v03] ... [vnn]
Consider the names without brackets as directory names and [name] as variables' names, programs included. If [prog1] uses any of the variables in VAR1 directory and you are sure it runs error-free from the first to the last command, them [prog1] should look like this:
«
VAR1
(program's body)
UPDIR
»
All commands in
(program's body) will store in and recall from variables existing in VAR1. The only BIG warning is that If you refer to any variable that does not exist in VAR1 directory and, for any reason, you have another variable with the same name in HOME or PRGM1, this variable will be reached by the program. This is because the HP48 O.S. searches for existing variables in the current directory AND, if it is not found, up in the directory tree till HOME. Then, if there are no variables with the same name, an error occurs. Even if it sounds awkward, this allows you to read the contents of any variable (even run a program) already existing in any upper directory from another program in a subdirectory. You cannot directly write on these variables without changing the current "path".
What I normally do is to use an input program that creates compiled local variables (the ones with names begining with <-), then I call a "subprogram" that switches to the "variable's directory", like the example above. This "subprogram" is completely safe, runs error-free, may access the compiled local variables and is the only program that will read and write in the variables that exist in the "subdirectory" . At the end of it, the necessary results are placed in the stack and the UPDIR command is executed. When the final » is found, the O.S. is working again in the original directory were the main program is stored. Then the program takes the results from the stack and shows them the way you like it. This structure is functional and applicable when you have many variables and extensive manipulation. Small programs and a few variables may be kept in "small boxes", too. Just a guess.
I hope this helps you.
Cheers.