Comparing record with original when saving
Boaz Bezborodko
boaz at mirrotek.com
Wed Jan 17 08:15:14 PST 2007
If you have 32 "line items" with 5 fields per line item then you would
have a loop of between 1 and 160. Add the offset for the file record
comparison. (IOW, if the line-items start at field 10 then loop between
"1" and "160" and add "10" to the fields you are comparing.) To find
out which line item you are dealing with simply divide the current
instance of the loop by 5 and the integer is the particular line-item
you're dealing with. To find out which field then enter a line
something like this:
aa=MOD(n,"5")+"1"
Where 'n' is the instance in the loop. 'aa' will hold a number between
"1" and "5".
The idea of copying a file was documented in the FilePro manual under
"Clone Files" in "Advanced Concepts" under the "How Do I" section.
Here is a copy of the text:
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 didn't 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 can't 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
Jeff Harrison wrote:
> --- Boaz Bezborodko <boaz at mirrotek.com> wrote:
>
>
>>>> I believe that he wants to compare the current
>>>>
>> values
>> to the original values - if you want to do that at
>> the
>> time the record is saved, then I believe that you do
>> need an array to store the original values.
>>
>> The older Filepro manual has a solution for this
>> that doesn't use a lot
>> of code.
>>
>> What you do is create a qualifier for the file. On
>> entering update copy
>> the record to the qualified file and record the
>> record number of that
>> record in a dummy field. When saving the record run
>> a loop to compare
>> each field with the same field in the qualified
>> record. If you only
>> have to compare the item records then simply start
>> the loop at that
>> field. A simple MOD statement will tell you which
>> of the detail items
>> of the associated fields you are dealing with.
>>
>> When you're done you can delete the qualified
>> record.
>>
>> Boaz
>>
>>
>
> "simple MOD statement" ?? Can you give us some more
> detail here?
>
> It sounds like there would be quite a bit more IO with
> this approach - also, you mentioned that you would
> still need a loop... still if it is simplier to code I
> would be interested in hearing the details.
>
> Jeff Harrison
> jeffaharrison at yahoo.com
>
> Author of JHExport and JHImport. The fastest and
> easiest ways to export and import Filepro data.
>
>
>
> ____________________________________________________________________________________
> Don't pick lemons.
> See all the new 2007 cars at Yahoo! Autos.
> http://autos.yahoo.com/new_cars.html
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.celestial.com/pipermail/filepro-list/attachments/20070117/3972358b/attachment.html
More information about the Filepro-list
mailing list