I define a variable:
DEF VAR myvar AS INT.
How to undefine this varable ?
Message was edited by:
You can't, but tell us why you want to and maybe we can suggest something. E.g., it could be put in a sub-procedure and would be scoped to that subprocedure.
I have "DEF VAR myvar AS INT" statement in my .i file.
In case I call this file once - it is OK.
But when I try to call it once more I get an error because I can't define the same variable more than once. So I wanted to undefine the variable before calling this file for the second time.
AH, different problem.
The right solution is to change the structure. A fairly simple way to do this and generally a better approach than using include files anyway, is to encapsulate the code into a separate procedure to which you pass parameters.
If the code is small and specific to a single program, you can even make it an internal procedure where you can get away with (but shouldn't) interacting with the context of the program (but, if you are doing things right, everything will get passed in or out as a parameter). Since you can define variables local to the internal procedure, no problem.
If it is used in multiple programs, then put it in its own .p. If it is called repeatedly from the same procedure, then run it persistent and run an internal procedure in it as needed.
Now, since someone else will probably mention it if I don't, you can also use the preprocessor to handle this situation and stick with includes. The basic idea is that you check with the preprocessor to see whether something has been previously defined and only execute the define statement when it has not been defined.
But, do yourself a favor and don't go that route. It may seem faster right now, but it is really not the right way to solve the problem.
Thomas, thank you very much for your answer.