Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SCAN ENDSCAN with INSERT statment...
Message
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
OS:
Windows XP SP1
Miscellaneous
Thread ID:
00965286
Message ID:
00965290
Views:
8
>While investigating some scary VFP code for a data production problem I came across the following :
>
>
>SELECT MyTable
>SCAN
>  SCATTER TO laArray
>  FOR x=1 TO 9
>    DO CASE
>      CASE x=1 AND ...
>        laArray[22]=laArray[22]+"SA"
>        INSERT INTO MyTable FROM ARRAY laArray
>
>      CASE X=2 AND ...
>        laArray[22]=laArray[22]+"GA"
>        INSERT INTO MyTable FROM ARRAY laArray
>
>      CASE x=3 AND ...
>        laArray[22]=laArray[22]+"MF"
>        INSERT INTO MyTable FROM ARRAY laArray
>
>    ENDCASE
>  ENDFOR
>
>*** Process MyTable
>
>ENDSCAN
>
>
>The cause of the problem is the records INSERTED during the scan are never processed. Walking through the code in the DEBUGGER shows the MyTable hits EOF when on the record that was the last record when the SCAN started. I could reproduce the problem VFP 8 and VFP 9 earlier this week at the office. Support is upgrading production code to VFP 8.0 so I thought it was a upgrade problem but they assured me the problem began BEFORE the upgrade was put in place. Well tonight I just ran the same code in VFP 6 SP5 thinking it would work but that is not the case. Walking through the DEBUGGER I get the same results as I do in VFP 8 and VFP 9.
>
>The troubling part is this code has been running and working in a high-volume, production environment since 2000. The problem started on November 8th and production support has not been able to solve the problem so I was asked me to investigate.
>
>Maybe VFP 6.0 worked before installing the VFP 8.0 runtimes? I don't know all the update details of when, what and who yet.
>
>Any ideas?
>
>Thanks!

Is there an index order set? Are the inserted records being inserted into the table inserted at a position that has already been processed?

If no index order is set, check to see if the insert is changing the record pointer to the last record that was inserted? In my quick test when I insert a record in the scan loop, it moves the record pointer to the last record inserted which short circuits the loop causing it to exit without processing any other record after the insert. It behaves like issuing go bottom within the scan loop But if I save the record number prior to the insert, then return back to that same record after the insert, it processes all records including the newly inserted records. Unfortunately this will not work if there is an index order set since the inserted records may be placed in the index order before the last record processed in the scan.

I suggest checking your loop to determine if the insert is changing the record pointer.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform