|
Hi David,
>
> Does anyone know of an example that uses the CEE4RAGE API in RPG?
>
Here's a message that I posted to the iSeries Network RPG forum back in
May. It was in reply to someone who wanted to run procedures when a service
program was activated or deactivated (much like a constructor/destructor
in OO languages.)
---------------------------------------------------------------------
Date: May 24, 2004 10:49 AM
Author: Scott Klement (sklement@xxxxxxxxxxxxxxxxxx)
Subject: Here's how I do it...
As far as I know, there's no way to run a procedure during the activation
phase.
Here's how I approach the problem: I have a subprocedure that gets called
first by every exported subprocedure. I use a global field to determine
if it's been called before, and if so, it does not run again.
I also tend to register a cleanup procedure with CEE4RAGE. Though,
ending the activation group should theoretically clean everything
up for me, I like to do it explicitly. I like to be in control! :)
The following code should help illustrate what I'm talking about:
H NOMAIN
D Initialized s 1N inz(*off)
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* 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
// ... terminate any helper processes
// ... shut down any persistent APIs
// ... close files.
// ... deallocate memory.
Initialized = *OFF;
return;
/end-free
P E
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Every exported procedure (besides EndSrvPgm) starts by calling
* the InzSrvPgm() subprocedure
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
P SomeProc B export
D SomeProc PI 10I 0
D SomeParm 123A const
/free
InzSrvPgm();
// ... perform function of subproc here ...
return data;
/end-free
P E
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Every exported procedure (besides EndSrvPgm) starts by calling
* the InzSrvPgm() subprocedure
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
P AnotherProc B export
D AnotherProc PI 10I 0
D AnotherParm 321A const
/free
InzSrvPgm();
// ... perform function of subproc here ...
return data;
/end-free
P E
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.