<< When using nested RUN <program> USING varlist, should the "CLEAR VAR __-_" command to clear the passed variables be used after each RUN . . . .USING command or will that foul things up? >>
Mike: Here's what I learned to do from Dennis McGrath (or maybe Bill Downall, those guys look so much alike), years ago: The CLEAR VAR __-_ goes INSIDE the program you're RUNning. The first thing you do inside that program is assign % variables to "real" variable names and then get rid of the % variables. I've elaborated this a little over time, so if I have a routine that takes two parameters, (let's imagine CustID and an optional Limit value) my code would look like this: $COMMAND MyRoutine SET VAR vMR_CustID INT = NULL SET VAR vMR_Limit INT = NULL SET VAR vMR_CustID = (.%1) SET VAR vMR_Limit = (.%2) CLEAR VAR __-_ IF vMR_CustID IS NULL THEN PAUSE 2 USING 'MyRoutine called without required CustID parameter' GOTO CleanUp ENDIF -- Routine here LABEL CleanUp CLEAR VAR vMR_% RETURN The use of "vMR_" before each variable is my attempt to implement something a little bit like local scope in R:Base, which has only global variables. The idea is that no other routine in my application will use this variable prefix, so variables will never "stomp" on each other, and all variables can be cleared at the end of the routine. Clearing all the % variables is to solve the problem of R:Base sometimes not clearing them, and getting mixed up from RUN to RUN. Checking to ensure that a non-NULL CustID was passed in is my attempt to duplicate function signatures that check their own input in other languages. Finally, exiting the program only through the LABEL CleanUp rather than RETURNing in the middle of the code is also there to account for the fact that R:Base doesn't have a local scope to dissolve when the routine returns, so I have to ensure I do it myself. This adds a fair amount of overhead to my routines but I never have variable passing or stomping issues, and I'm able to keep memory relatively free of extraneous variables without having to check a bunch of CLEAR VAR statements every time I modify a routine. -- Larry

