Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SCAN ENDSCAN with INSERT statment...
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
OS:
Windows XP SP1
Divers
Thread ID:
00965286
Message ID:
00965648
Vues:
9
>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?
>

Hi there,

This code is kind of 'asking for trouble' :)
U can achieve much cleaner solution, by inserting new records into temporary cursor of the same structure while scaning original table and then simply dump them in after main scan is done.

so code cld look something like this ;
SELECT MyTable
local aStru(1)
afields(aStru)
create cursor tmpTable from array aStru
SELECT MyTable
go top
scan
   .
   scatter to laArray
   .
   do case
    
     case ...
     insert into tmpTable from array laArray

     case ...

   endcase
   .
endscan
.
append from tMyTable 
.
Rgds++
*****************
Srdjan Djordjevic
Limassol, Cyprus

Free Reporting Framework for VFP9 ;
www.Report-Sculptor.Com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform