× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



David,
Specifying USROPN for your files and then doing a check to see if the file
is open already using the following code can save you a ton of processing
time. Opening and closing files all the time can be very expensive
especially for modules/procedures that are very detailed and called a lot.

if not %open(filename);
open filename;
endif;

I use some code from Scott in my module source that checks for open files
when the activation group is destroyed and the service program's storage
is reclaimed. It consists of a lot of...
if %open(filename);
close filename;
endif;

This will only close up the files one time and happens behind the scenes
after you would have returned to your menu.

A note about the code below.... In the Initialized procedure it says
//..open files here...

I don't open my files here because I often have multiple procedures in the
same module source member and they aren't always used, so I open them at
the beginning of each procedure. But I close ALL the files in the
EndSrvPgm procedure. This saves from opening files that aren't needed and
keeps overhead down a little on startup.

///////////////////////////////////////////////////////
D Initialized s 1N inz(*off)

D InzSrvPgm PR
D EndSrvPgm PR
D AgMark 10U 0 options(*nopass)
D Reason 10U 0 options(*nopass)
D Result 10U 0 options(*nopass)
D UserRC 10U 0 options(*nopass)
D
D OEI032R PR extpgm('OEI032R')
D order 6 0
D line 3 0
D item 15a
D adjop 3 0
D newhrs 8 3
D omitop 3 0
D
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Initialization routine
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
P InzSrvPgm B
D InzSrvPgm PI

D CEE4RAGE PR
D procedure * procptr const
D feedback 12A options(*omit)

/free
if (Initialized);
return;
endif;

// .. open files here ...
// .. other initializations ...

CEE4RAGE(%paddr(EndSrvPgm): *OMIT);

Initialized = *ON;
return;
/end-free
P e

*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* EndSrvPgm(): This is called automatically when the activation
* group ends. (which is when the srvpgm is removed
* from memory.)
*
* Note that this must be exported so that CEE4RAGE can call it.
*
* InzSrvPgm() registers this procedure with the CEE4RAGE() API
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
P EndSrvPgm B export
D EndSrvPgm PI
D AgMark 10U 0 options(*nopass)
D Reason 10U 0 options(*nopass)
D Result 10U 0 options(*nopass)
D UserRC 10U 0 options(*nopass)
/free
if %open(filename);
close filename;
endif;

if %open(filename2);
close filename2;
endif;

// ... terminate any helper processes
// ... shut down any persistent APIs
// ... close files.
// ... deallocate memory.


Initialized = *OFF;
return;
/end-free
P E

Thanks
Bryce Martin
Programmer/Analyst I
570-546-4777



David FOXWELL <David.FOXWELL@xxxxxxxxx>
Sent by: rpg400-l-bounces@xxxxxxxxxxxx
12/28/2009 10:45 AM
Please respond to
RPG programming on the IBM i / System i <rpg400-l@xxxxxxxxxxxx>


To
RPG programming on the IBM i / System i <rpg400-l@xxxxxxxxxxxx>
cc

Subject
RPG Performance question






Hi all,

I often notice a significant time lapse when exiting client management
applications and returning to a menu. Noticing the difference in the list
of files (with wrkjob) that I can see that are open during running of the
main rpg code and the empty list on returning to the menu, I was wondering
if all the closing of files was at least partially to blame. Files can
appear on the list of files open several times. This is because they are
declared in several modules bound (by copy) to the same program.Is this
something to be avoided, or is the performance cost negligible?

Thanks


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 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.