I am looking for a technique that would allow me to clear the physical file upon the completion of the trigger program. I attempted to do this at the end of the CL porgram only to get the error message that the file is still in use. Apparently this is because the trigger program is still executing. Any suggestions on how to handle this scenario?
Software/Hardware used:
ASKED:
September 7, 2005 11:45 AM
UPDATED:
November 9, 2009 4:57 PM
If I understand correctly that you’re trying to do a CLRPFM on the same file which is causing the trigger to fire, here are a few things to consider:
1) CLRPFM requires *OBJMGT authority. That’s generally not wise to give to *PUBLIC. Since this is coded in a trigger, you don’t know who’s going to be executing your trigger — although you can deduce that it would only be people with the add, change, or delete authority to the file/table causing the trigger to fire.
2) The trigger would have to be an *AFTER trigger. The file will likely still be in use even after completion of the trigger. The function which caused the trigger to fire technically doesn’t complete until the trigger returns control and whatever other processing the original function needed to do is complete. I would set up a utility to request the file be cleared at a later time.
3) If there’s a problem with the file having records left for someone else (another function or invocation of the same program) to deal with, then you could delete the records — but you’ll have to watch out for record locking issues.
Are you certain you want to use a trigger or would a stored procedure containing all the logic be more effective?
I’m going to assume you’re talking about an *AFTER trigger.
That message is issued because the CLRPFM command, which you must be using, must allocate the file exclusivelly to execute.
On the other hand, a program, in RPG ILE for example, can read and delete all the records without the need of an exclusive allocation of the file.
SInce the file is still locked, you cannot do a CLRPFM.
As mentioned here, you can have a RPG program go through and delete all the records.
Another option is to use SQL and do a DELETE.
++
My question is if this trigger is initiated on every write to the file, you should have the trigger program delete ONLY that record. You will never be able to do an update to the file, because it should always be empty. If you do a CLRPFM or SQL DELETE to get rid of call the records, you are doing overkill since it is impossible to have more than one record in the file.