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




So does this boil down to just a few choices?
1 - Explicitly open and close the file all the time.

Personally, I code a subprocedure called "init" (or whatever you like) that opens all of the files. In each of the exported procedures, I code this as the first few statements:

    init();

The init subprocedure sets an indicator to keep track of whwther the files are open or close. If they're already open, calling init() a second time is a no-op.

Basically, the init() procedure looks like this:

   /free
         if (FilesOpen);
            return;
         endif;

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

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

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

         FilesOpen = *ON;
   /end-free

Like I said... every other exported subprocedure in the module calls this one as it's first line of code. The goal is that the first call to the module will cause the files to open. Subsequent calls won't do anything.

Then, I also have a done() procedure that closes the files:

   /free
        close *all;
        FilesOpen = *OFF;
   /end-free

In many of my service programs, this subprocedure is never called, but it stops the warning messsages from the compile. In other service programs, I'll insert code into my init() procedure that uses the CEE4RAGE() API to register the done() procedure to be called automatically when the activation group ends. That way, I can use it to clean up temporary objects, like user spaces or data queues, that wouldn't be automatically deleted by ending the activation group.

This way, my files are opened ONCE, not repeatedly. And they're closed ONCE when the activation group ends.


2 - Use ACTGRP(*NEW) on CRTPGM and explicitly close the file to eliminate
the warning messages.  The AG will implicitly open the file.

That works, too... but I don't like to start a new activation group on a call to a service program. As far as the srvpgm is concerned, it's always "loaded forever". If the caller wants to unload it by using ACTGRP(*NEW) or RCLACTGRP, that's the caller's responsiblity, not the srvpgm. (but, that's why I often use CEE4RAGE, to ensure that if the caller does end the activation group, everything is cleaned up nicely.)


3 - Implicitly open the file, don't worry about closing it, and ignore the
compile warning messages about close.

I never do that -- and it's not that I really care about the warning message, it just doesn't seem intuitive to me. There's no other programming language anywhere where the programmer expects the runtime to magically open and close the files for you, why should RPG be different?


Would setting on the LR indicator do anything?


No. LR has no impact on a NOMAIN module. (Activation groups were created as a way of enabling LR-like behavior across multuple languages. I suggest forgetting about LR and other cycle-driven stuff, and use activation groups instead. But it's not worth fighting about, so please don't turn this into a "holy war.")

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.