ISINFOA last modified datetime
To have an option in ISINFOA to return the last modified datetime stamp (same precision as %datetime) of a file on the nominated channel
LastModifiedDate = %ISINFOA (Channel,'LASTMODIFIED')
If you want your program to watch/monitor a file and when there is a data change in the file (Store, Write, Delete) perform some action.
ISCLR and ISAMC would initialise the value as they do for CLEARDATE and CREATEDATE values in ISINFOA; BLDISM would also initialise the value.
A data change could be from within the same program or from a completely unrelated program which updates the same data file.
example:
while (exit == %false) begin ; run until exit
mod_datetime = %isinfoa (channel,"MODIFIEDDAT") ; retrieve the last modified time on the file
if (mod_datetime != last_mod_datetime) ; has the file changed
begin
call refresh_display ; File has changed so redisplay the information
last_mod_datetime = mod_datetime ; Save last modified datetime stamp
end
exit = %check_program_status ; Check the other parameters to determine if exit required
if (exit == %false) sleep timer ; sleep nominated seconds before checking again
end
close
stop
One way to achieve this today is to use IOHOOKS and set an external value when the file is updated (STORE,WRITE, DELETE) but this has performance overheads.
Alternatively the program could monitor the Modified Date on the file system by shelling out and capturing the Modified Date but this relies on using the FLUSH statement to force data to be written to disk so that the Last Modified Date is updated on the file system. Also it would require different versions of the subroutine for Windows, Linux and VMS. There is a performance overhead in using FLUSH.
By using ISINFOA to determine if the file data had changed, it would avoid reading the entire file being monitored or another file containing the IOHOOKS trigger info, thereby only performing your action (redisplaying the screen) when it is necessary .
For example, If you want to monitor the revision time for an ISAM file, you can open the data file and run GETFA on the open channel, e.g.:
open(filechanis1,I:S,filename+".is1")
getfa(filechanis1,"RDT",result)
writes(ttch,filename + ".is1 last revised at " + result)
Sample output:
DAT:file1.is1 last revised at 17-APR-2018 12:13:09
This code only opens the data file (.is1), because that file is modified after any store, write, or delete operation. The index file (.ism), on the other hand, is only updated when the index changes, such as when a record is added or deleted.
Note that the revision time the OS provides for a file might be the most recent time that the file on disk is modified, rather than the time of the most recent operation that modified a record. It's possible that the RDT value won't change until the program modifying the file closes the files channel, flushing the changes to the disk. This behavior will vary between different Operating Systems and configurations, so you may want to test it for yourself. If a dbl program is updating the file, you can force it to update the value more frequently by calling FLUSH after every file output operation, but this would add additional overhead.
Because of this potential limitation, this approach might not be well suited for real-time file monitoring, as in the example above. But for more general purposes, GETFA & RDT could be helpful if you want a program to determine when a file was modified.
4/18/2018, 8:39 PM 0
9/17/2020, 9:32 PM 0