Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to make this code faster
Message
From
02/05/2013 12:29:34
Mk Sharma
Shrishti Solutions
Mumbai, India
 
 
To
02/05/2013 12:17:19
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows XP
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01572484
Message ID:
01572499
Views:
57
USEFILE() is to use and select the dbf file.
** usefile.prg
Lparameter m.FILENAME, m.AFILENAME
If Empty(m.AFILENAME)
	AFILENAME = m.FILENAME
Endif
Local FILENAME2
FILENAME2 = Alltrim(OAPP.ZDATAPATH) + m.FILENAME
If Not Used(m.AFILENAME)
	Use (m.FILENAME2) Again In 0 Alias (m.AFILENAME) Shared
	Select (m.AFILENAME)
	Go Top
Endif
Select (m.AFILENAME)
How REPLACE can change the order of records ?

Is below code can change order in table " cuttct " ?
Select cuttct
set order to takano

Select cuttct
Scan
   lntakano = takano
   If Not Empty(m.lntakano)
      **    Below code taking Maximum time in Coverage result
      Replace packed With ' ', packno With 0, recuttno With 0 In cuttct
      If Seek(m.lntakano, 'packtc', 'takano')
         lcmasterid	= packtc.MASTERID
         lnpackno	= Iif(Seek(m.lcmasterid, 'packtm', 'masterid'), packtm.packno, 0)
         **    Below code taking Maximum time in Coverage result
         Replace packed With Iif(m.lnpackno <> 0, 'Y', ' '), packno With m.lnpackno In cuttct
   Endif
Endscan
Warm regards,
mk.



>Well, I don't know about faster, but it won't work correctly. The record pointer is being moved inside the SCAN (replace can change where the current record is) and not reset. REPLACE is particularly problematic as it actually can change the order of the records and cause some to be processed multiple times and others not at all.
>
>Other things, you can combine SELECT and ORDER into on line
>SET ORDER TO tag IN alias
>
>You don't provide the code for UseFile function, so there's no way to know if that can be sped up.
>
>Seek() can be replaced with SET RELATION
>
>
>>How to make this code faster with Sql - Update or any other way ?
>>
>>
>>*- updtakastk.prg
>>****
>>Local lcmasterid, lnavgrec1, lnavgrec2, lnavgrec3, lnpackno, lntakano, lntotrec, lntrnno
>>USEFILE('cuttm')
>>USEFILE('cuttct')
>>USEFILE('packtc')
>>lntakano = 0
>>Select cuttm
>>Set Order To takano
>>Select cuttct
>>Set Order To takano
>>Select packtm
>>Set Order To MASTERID
>>Select packtc
>>Set Order To takano
>>Select cuttct
>>
>>Wait Window 'Working... Please Wait...' At Srows() / 2, Scols() / 2  Nowait
>>
>>Select cuttct
>>Scan
>>
>>   lntakano = takano
>>   If Not Empty(m.lntakano)
>>      **    Below code taking Maximum time in Coverage result
>>      Replace packed With ' ', packno With 0, recuttno With 0 In cuttct
>>      If Seek(m.lntakano, 'packtc', 'takano')
>>         lcmasterid	= packtc.MASTERID
>>         lnpackno	= Iif(Seek(m.lcmasterid, 'packtm', 'masterid'), packtm.packno, 0)
>>         **    Below code taking Maximum time in Coverage result
>>         Replace packed With Iif(m.lnpackno <> 0, 'Y', ' '), packno With m.lnpackno In cuttct
>>      Else
>>         lntrnno =	Iif(Seek(m.lntakano, 'cuttm', 'takano'), cuttm.trnno, 0)
>>         Replace packed With Iif(m.lntrnno <> 0, 'Y', ' '), recuttno With m.lntrnno In cuttct
>>
>>         lntrnno =	Iif(Seek(m.lntakano, 'cuttm', 'takano1'), cuttm.trnno, 0)
>>         Replace packed With Iif(m.lntrnno <> 0, 'Y', ' '), recuttno With m.lntrnno In cuttct
>>      Endif
>>   Endif
>>Endscan
>>Wait Clear
>>
>>
>>
>>Warm regards,
>>mk.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform