Go Back
3 Votes

ISINFOA last modified datetime


Closed

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 .

2 Comments | Posted by Geoff MacCue to Synergy DBL on 3/21/2018, 3:59 AM
Phillip Bratt
Synergy does provide functionality similar to this. If you use the GETFA subroutine using the 'RDT' keyword, it will query the Operating System for the revision date and time for an open file.
 
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  
Steve Ives
We've been doing some research on this, and it turns out that we don't think we can offer any added value over what GETFA already does (discussed above). When you edit a file, in a text editor for example, and save the changes, the file is essentially completely overwritten and the O/S records the date of last update. But when you open a file and make specific targeted changes to it (like a DBL WRITE or STORE statement does) the operating system does not always record that information, end even if it does, it is likely to be cached and not happen immediately. And that makes sense if you think about it; I'magine the additional overhead if the O/S had to update the last access time every time a record is updated. So GETFA(RDT) is already there for you, but be aware that it's not that accurate, so don't base critical stuff on the information.

9/17/2020, 9:32 PM   0  
Please log in to comment on this idea.