# Clone Files

Big Hint: Making a clone file can save your act. Keep an audit trail of everything that happens to a particular data set. If you have ever had a user tell you "I didnt do that" and you can see that they were the last person to update the file, it makes for a difficult session. You "think" they might have been the one, but you cant say for sure. Here is the solution. On the files where you have this kind of trouble, or on any file for which you want to keep accurate track of every change, do the following: store exactly what happens to each field of the record from the time it is created; every single change along with date/time/user stamp. You will never have to guess again.

The idea is simple and it can be carried out in a variety of ways. Here is how I do it.

1. Build a "logging file" to capture the log information. This file should have fields for containing the filename, the process name, the field #, the unique ref # for the record, the original data, the changed data and the date/time/who for any file you wish to track. The original data field and changed data field should be 79 characters long. Call this file something like "myprefixlog".

2. First, I copy the file I wish to track with "fpcopy". Only the file structure is necessary, nothing else. Give the new file the name "oldfilename.l" for "log".

3. Next, build an array in the "input" table of the file to be tracked that contains every record in the file.

Dim clone[#]:1

Where # is the number of fields in the file.

4. Whenever there is a possibility that fields may change, do a lookup free to filename.1 and build a similar array over that file and immediately copy the original file/record to the clone file/record.

5. When the record is finally stored, compare the two arrays element by element. If any field has changed, write the original value, the changed value and the date/time/who into your actual log file (myprefixlog).

6. By indexing "myprefixlog" correctly, you can instantly see every change in chronological order for any file.

Here is an example of this code. Your values would have to change to suit one of your own files.

This snippet has to be "atomically" close to the real END statement of your processing table.

If: clone

Then: gosub changed

If:

Then: end

As soon as there is a chance that some fields may change, you must get the free record in the clone file. This is a simple gosub.

@keyU if:

then: gosub clonit

The actual cloning code looks like this:

If:

Then: lookup clone=npio r=free e

If:

Then: copy clone

If:

Then: dim before[566]:clone(1) ; write clone

If:

Then: c(8,.0)=clone(@rn) ; return