Dynamically retrieve handles to all temp-tables and workfiles

D.Cook

Member
I'm in a situation where I need to get references to all temp-tables and/or workfiles in a procedure so I can empty them.

Of course being the good programmer I am, I should always clean them up in my code.. but no-one's perfect. I was hoping to create a utility function to loop through all temp-tables/workfiles and empty each one.

I'd hoped for something like THIS-PROCEDURE:FIRST-TEMP-TABLE but can't seem to find what I need. Any suggestions?
 
At the PEG the following rules where posted a long time ago about cleanup of dynamic objects. I think they mostly still apply:
The following rules apply to cleanup of dynamic objects, a dynamic object is everything created with the create statement.
  • Rule 1: If you create it, you delete it
    • If you didn’t create it, you don’t delete it
    • Any procedure which will not have enough information to know when to delete a dynamic object shouldn't be creating it
  • Rule 2: There are only two valid patterns for creating a dynamic object, inline and factory
    • Inline: All inline creations look like this:
      create object-type x.
      do on endkey undo, leave on error undo, leave on quit undo, leave on stop undo, leave:
      /* Work with object */
      end /* do on ... */.
      delete object x.
      assign x = ? /* Not sure this is still necessary - can't hurt */.
    • Factory: There is a persistent/super procedure responsible for the particular implementation of object X, usually it wil be responsible for all objects. And therefore have procedures/functions like:
      assign x = createAnObjectOfTypex ( creation, parameters ).
      run deleteThisObjectOfThisType ( x ) or
      publish "ImDoneWithThisObject" ( x ).
  • Rule 3: Any object which has a factory should be created within that factory. Inline creation is only for objects which are not managed by a factory.
  • Rule 4: Use widget-pool if you turn control outside of the framework:
    create widget-pool.
    do on endkey undo, leave on error undo, leave on quit undo, leave on stop undo, leave :
    Run Value(codedeveloppedoutsideframework).
    end.
    delete widget-pool.
Rule 5: Appserver super/persistent procedure should always first cleanup previous call before proceeding.

If you follow these rules then there is no need to make a program which tries to correct programming errors of others. Maybe nobody is perfect, but if you follow these rules then you can force cleanup to be be handled at the right place.
(There are some problematic parts with regards to cleanup of dynamically created objects but that is a different story..)

Casper.
 
I think SESSION:FIRST-BUFFER might be what you want. I am not sure what the exact relationship is with CREATE TABLE and like statements. It's one of those things I'd like to understand in detail. I also really wish P4GL had a simple wayto see all memory use in detail.
 
session:first-buffer could get you there, but it only works on dynamically created buffers. You can use the table-handle attribute of the buffer to get the handle of the temp-table the buffer is created for. I don't think this works for work-files though and as said... it only works with dynamic buffers.
 
Thanks for the suggestions guys.
I might see what I can achieve with SESSION:FIRST-BUFFER; but I think the best way to go will just be adhering to the PEG rules...
 
Back
Top