Finding out what file is OUTPUT TO directing output to

cdcastroi

New Member
Hello everyone.

If I define the following sentence:

OUTPUT TO file.txt.

Then I call several external procedures. How can I get the file name (file.txt) OUTPUT TO is using to output data within the called procedure?

The file name is randomly generated everytime the application is executed.

I cannot use neither shared variables nor parameters to pass the file name to the following procedures.

Thanks and regards.
 
1. Save it somewhere like the registry or to disk
2. Use a global variable
3. Use SOURCE-PROCEDURE

There are lots of options really. If you are not too fussed about using global variables then this is by far the simplest method. In the procedure that has the OUTPUT TO statement, define a global variable like this:

DEFINE NEW GLOBAL SHARED VARIABLE gvFile AS CHARACTER NO-UNDO.

Then assign it to the output filename. In your sub-procedures, define the same variable in exactly the same way, and the sub-procedure will have access to the value stored.

The other SOURCE-PROCEDURE method is more fiddly. When you run your sub-procedures, they can find out who ran them by examining the SOURCE-PROCEDURE handle. So you can work your way back-up the call stack to the procedure that opened the output stream. You can then ask it (by running an internal procedure or function) for the filename that it used.
 
Back
Top