|
James, As Paul already indicated, you can accomplish what you're after by using activation groups, or a clean-up procedure. Paul's code already shows you how to handle the open on first call of the procedure. Now you simply create another procedure to handle the close and have the calling procedure invoke it whenever appropriate. Here is an example of the two procedures: P GetCustName B D PI 50A D iAccount 7S 0 Const C If Not %Open( CUSTMAST ) C Open CUSTMAST C Endif * Do your processing and return P GetCustName E P CleanUp B C If %Open( CUSTMAST ) C Close CUSTMAST C Endif C Return P CleanUp E Now the calling procedure: P Caller B D CustomerA 50A D CustomerB 50A D CustomerC 50A C Eval CustomerA = GetCustName( 100 ) C Eval CustomerB = GetCustName( 101 ) C Eval CustomerC = GetCustName( 102 ) C CallP CleanUp P Caller E If you want to avoid the CleanUp procedure, compile the calling procedure into a named or *NEW activation group. If the GetCustName procedure is bound by copy into the program, then there is nothing left to do. When the program ends make sure that the activation group also ends (automatic if using *NEW). The system will close the file when the activation group is destroyed. On the other hand, if the GetCustName procedure is part of a service program, then you need to make sure that the service program was compiled with ACTGRP(*CALLER) if you want the file closed when the calling pgm ends. HTH, John Taylor Canada ----- Original Message ----- From: "James David Rich" <james@dansfoods.com> To: <RPG400-L@midrange.com> Sent: Thursday, March 02, 2000 09:25 Subject: Re: using files within subprocedures > On Wed, 1 Mar 2000 pcunnane@learningco.com wrote: > > Code the file with USROPN. In the procedure: > > > > if not %open(CUSTMAST) > > open CUSTMAST > > endif > > > > You will want a cleanup routine to explicitly close the file, or allow > > it to be closed when the activation group ends. > > Ah - there's the rub. How do I code it so that the file is opened on > first invocation (that is what you have above) and closed when the calling > program exits (*not* when the procedure exits). > > James Rich > james@dansfoods.com > > +--- > | This is the RPG/400 Mailing List! > | To submit a new message, send your mail to RPG400-L@midrange.com. > | To subscribe to this list send email to RPG400-L-SUB@midrange.com. > | To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com. > | Questions should be directed to the list owner/operator: david@midrange.com > +--- +--- | This is the RPG/400 Mailing List! | To submit a new message, send your mail to RPG400-L@midrange.com. | To subscribe to this list send email to RPG400-L-SUB@midrange.com. | To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: david@midrange.com +---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.