× 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.



+1

I'd forgot to mention this - and I advocate this in my COMMON presentation.

Just to emphasize what you have in the sample below - one must deallocate the memory in the CLOSE support.

Vern

On 10/20/2017 7:55 AM, Barbara Morris wrote:
On 2017-10-19 9:49 AM, dlclark@xxxxxxxxxxxxxxxx wrote:
...          The handler is in memory for the call from the second program and
apparently has some variables also in memory that aren't getting
reinitialized for each call.  That is also why RCLRSC works -- because it
forces the handler out of memory so that it gets new storage for its
variables when it is loaded again.  The solution is to make sure global
variable storage is reinitialized when either the calling program or
requested file changes.


Another way to handle multiple files is to use the "state info" mechanism to have a separate set of "global" data for each file. It would be necessary to use this mechanism if it was possible that a program with an OA file might call another program with an OA file, so the calls to the handler would be interleaved.

Create a data structure template with a subfield for each global variable. Then, while handling the open for the file, allocate the storage for the basing pointer of a "globals" based data structure and initialize the subfields, and also put the pointer in the stateInfo pointer of the handler parameter. On subsequent calls to the handler, use the stateInfo pointer to set the basing pointer for a based "globals" data structure.

dcl-ds globals_t qualified template;
   something char(1);
   whatever int(10);
end-ds;
dcl-ds globals likeds(globals_t) based(pGlobals);

   if parm.rpgOperation = QrnOperation_OPEN;
      // allocate globals for this file
      pGlobals = %alloc(%size(globals_t));
      parm.stateInfo = pGlobals;
      // initialize globals for this file
      globals.something = 'x';
      globals.whatever = 5;
   elseif parm.rpgOperation = QrnOperation_CLOSE;
      pGlobals = parm.stateInfo;
      ... do regular close stuff
      dealloc(n) parm.stateInfo;
      pGlobals = *null;
   elseif .... ;  // some other operation
      pGlobals = parm.stateInfo;
   ...



As an Amazon Associate we earn from qualifying purchases.

This thread ...

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.