>more like ..
>select FileToAppend && Its actually a blank cursor
>zap
>Select FileToRead
>gotop
>scan && !eof()
>Match=FileToRead.Field1
>Total=0
>scan while FileToRead.Field1=Match
>Total=Total+FileToRead.Field2
>appen blank in 'FileToAppend' && Works okay here
>repl FileToAppend.Field1 with FileToRead.Field1,FileToAppend.Field2 with FileToRead.Field2
>endscan &&while FileToRead.Field1=Match
>appen blank in 'FileToAppend' && Works okay here except for eof()
>repl FileToAppend.Field1 with "Total",FileToAppend.Field2 with Total && Adds a blank record but does not replace **UNLESS**
>endscan &&!eof()
>
>**UNLESS**
>I use the following syntax:
>Select FileToAppend
>append blank
>replace .....
>select FileToRead
>endscan &&!eof() , etc.
The reason is that VFP's REPLACE verb won't update the record in another work area if the work area you're in is positioned on the phantom record in the current work area; by changing which workarea you're on, you change to the work area that's -not- at EOF() and find that you can update...
I'd suggest changing to something like:
select FileToAppend
zap
Select FileToRead
go top
DO WHILE ! EOF()
Match=FileToRead.Field1
Total=0
SCAN while FileToRead.Field1=Match
Total=Total+FileToRead.Field2
INSERT INTO FileToAppend VALUES (FileToRead.Field1, FileToRead.Field2)
endscan
INSERT INTO FileToAppend VALUES ('Total',Total)
ENDDO
This also avoids a logic bug caused by using two SCANs; each ENDSCAN causes a SKIP, so the first record of each subsequent group is lost in your original code. You can also add an IN clause to your REPLACE that specifies which target workarea you intend to reference rather than use
alias.fieldname:
REPLACE Field1 WITH 'Total', Field2 WITH Total
IN FileToAppend