Reclaim Resources Vs Closedown Program

23 Views


This is where people often confuse “Reclaim Resources” in a Synon function option with the Closedown Program (a separate system concept). Let’s carefully separate them:


🔹 1. Reclaim Resources (Function Option in Synon)

  • Scope: Applies to that function only.

  • What it does:

    • Tells Synon whether, when the function ends, it should release resources (files, ODPs, memory, locks, commitment control).

    • Yes → like ending with *INLR = *ON (everything freed).

    • No → like ending with RETURN (resources left open).

  • Purpose: Performance tuning & resource control for function chaining.

  • Level: Micro-level, per-function basis.


🔹 2. Closedown Program

  • Scope: Applies to an entire job or application session.

  • What it does:

    • A Closedown program is a Synon-defined utility function that is automatically called when a user exits the application (e.g., backs out of menus, presses F3/F12, or signs off).

    • It is responsible for:

      • Closing all open files (if still held).

      • Releasing any remaining resources not already reclaimed.

      • Doing final updates (audit trails, last-used info, cleanup).

      • Returning control back to the system or menu.

  • Purpose: Ensures the application shuts down cleanly, no matter what happened in individual functions.

  • Level: Macro-level, whole job/application basis.


🔹 How They Differ

Aspect Reclaim Resources Closedown Program
Scope Per-function (when that function ends) Entire job/session (when application exits)
Timing Immediately after function completes At application termination
Control Developer sets Yes/No on each function One designated program per model/application
Purpose Optimize performance (keep ODPs vs. free them) Guarantee clean shutdown of all resources
Example After an Inquiry function ends, files may stay open if Reclaim=No When user presses F3 from main menu, Closedown program runs and ensures everything is freed

✅ Example to Visualize

  • Suppose you have a menu-driven app with 5 inquiry/update functions:

    • Each function might have Reclaim = No so they keep files open → faster navigation.

  • At the very end, when the user exits the app, the Closedown Program runs → closes all those files, reclaims memory, ends commitment control.


👉 Think of Reclaim Resources as per-room cleanup 🧹 and the Closedown Program as the janitor locking up the entire building at night 🔒.


Awesome—here’s a clear, side-by-side look at what Synon (Cool:2E) typically generates under the hood, using RPG/CL equivalents for:

  • *Reclaim Resources = YES

  • *Reclaim Resources = NO

  • Closedown Program (runs when the user exits the app/session)


1) Reclaim Resources = *YES → like ending with LR

Intent: Free everything when the function ends (files, ODPs, memory, commitment definitions).

RPGLE sketch (single-module function)

**free
ctl-opt dftactgrp(*no) actgrp('APPGRP');

fCUSTPF    if   e           k disk    usropn;  // opened/closed by program

dcl-s rc int(10);

 // --- entry / setup ---
open CUSTPF;

 // --- main logic ---
exsr DoWork;

 // --- cleanup (Reclaim=YES) ---
*inlr = *on;            // signals end of job for this program's resources
return;                 // control returns to caller; files closed, storage freed

 // --- subroutines ---
begsr DoWork;
  // ... read/update ...
endsr;

What to note

  • *INLR = *ON ⇒ program’s files close, resources freed.

  • Next time you call this function, files re-open (more overhead but “clean”).


2) Reclaim Resources = *NO → RETURN without LR

Intent: Keep files/ODPs open so subsequent functions in the same activation group can reuse them (faster chaining).

RPGLE sketch (single-module function)

**free
ctl-opt dftactgrp(*no) actgrp('APPGRP');

fCUSTPF    if   e           k disk    usropn;  // USROPN allows reuse

dcl-s alreadyOpen ind inz(*off);

 // Example pattern if you cache “open state” somewhere (service pgm/global)
if not alreadyOpen;
  open CUSTPF;
  alreadyOpen = *on;
endif;

exsr DoWork;

// No LR here — return with ODP still open
return;

begsr DoWork;
  // ... read/update with index already built & ODP warm ...
endsr;

What to note

  • No *INLR → ODP and storage remain until activation group ends.

  • Great for menu flows where you enter/exit different functions frequently.

  • Caution: can hold locks if you forget to commit/close properly.


3) Closedown Program (whole app/session cleanup)

Intent: When the user exits the application, the closedown program runs once to clean everything—regardless of each function’s Reclaim setting.

You can implement it as a CL program (often called from the main menu Exit/F3):

CL example (CLOSDWN)

pgm

   /* If using commitment control, ensure a clean end */
   monmsg cpf0000

   /* Example: end commitment control if active */
   dcl  &CMTCTL *char 10
   rtvjoba cmtctl(&CMTCTL)
   if   cond(&CMTCTL *eq '*CHG') do
      /* your commit/rollback policy here; typically commit outstanding work, then end */
      /* COMMIT           */
      endcmtctl
   enddo

   /* If using adopted resources or semaphores—release them here */

   /* Optionally call a service program/API that:
      - Closes any USROPN files left open
      - Flushes logs/audit
      - Frees heap storage, qtmh allocations, etc.
   */

   /* End the activation group if the app uses a named one */
   /* For ILE, you usually let the caller end it (menu framework).
      But if you own it, you could: */
   /* RCLACTGR ACTGR(APPGRP)  <-- Reclaims resources in that actgrp */

   return
endpgm

Optional: “Central close” in RPG service program

If you’ve been leaving files open with Reclaim=*NO, have a central routine to close them:

**free
ctl-opt nomain dftactgrp(*no) actgrp('APPGRP');

fCUSTPF    if   e           k disk    usropn;
fORDRPF    if   e           k disk    usropn;

dcl-proc CloseAllFiles export;
  if %open(CUSTPF); close CUSTPF; endif;
  if %open(ORDRPF); close ORDRPF; endif;
  // ... any others ...
end-proc;

Then your Closedown CL can call an RPG wrapper that invokes CloseAllFiles.


How they differ—practically

Concern Reclaim=*YES Reclaim=*NO Closedown Program
When it runs At function end At function end At application exit
Scope That function That function Entire job/session
Files/ODPs Closed now Left open Ensures all are closed
Performance Reopen next time (slower) Reuse (faster) n/a (final cleanup)
Locks/Commit Freed Persists until group ends Freed/ended for good

Activation Groups (important glue)

  • If multiple functions share the same named activation group (e.g., APPGRP), using *Reclaim=NO lets them reuse open ODPs and memory → fast transitions.

  • The Closedown Program (or the framework that owns the menu) should end that activation group (or otherwise reclaim it), ensuring nothing leaks.


Quick Synon mapping tips

  • In Synon function options:

    • *Reclaim Resources = YES → think “*INLR = *ON on exit.”

    • *Reclaim Resources = NO → think “RETURN on exit; keep stuff warm.”

  • In your application definition, assign the Closedown Program so the framework calls it when the user backs out.


 

Post Comments