<quote who='Dennis Bartlett' date='Thursday 03 April 2008'>
> Hi
>
> I have a subroutine that WRITESEQ to a record in a type 1 file called
> INTEGRITY.
>
> Is there anyway I can open the file once (in the subroutine) and thereafter
> use the same file handle (to avoid opening the file each time the
> subroutine is called) ?
>
> All the code on this site opens the file in the calling routine and passes
> the handle to the subroutine.
>
> I want to rather make the subroutine a stand-alone, not requiring more than
> the subroutine call added to the calling programs.
>
> I have a suspicion I can use named common - if so, does this have to be
> declared in the calling routine (which would negate my purpose!).

Yes - I use this approach and it works fine.  In short, I build a COMMON array 
with file handles and a dynamic array with the names of the open files.

At first invocation, you need to check to see if the COMMON vars are 
initialized or not - if not, you initialize them.  Once this is done I merely 
look for a filename in the dynamic array, if found it returns the file handle 
for I/O.  If it's not present it opens the file, adds the filename to the 
list and you go on.

At the end of the process, it loops over all open file handles and closes 
them.  Depending on your application, you can figure out optimal places to 
open/close the file handles. 


-- 
Jeff Butera, Ph.D.
Administrative Systems
Hampshire College
[EMAIL PROTECTED]
413-559-5556

Where I'm from, we believe all sorts of
    things that aren't true. We call it "history".
                       The Wizard, Wicked
-------
u2-users mailing list
u2-users@listserver.u2ug.org
To unsubscribe please visit http://listserver.u2ug.org/

Reply via email to