Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update during SCAN / ENDSCAN ? 1

Status
Not open for further replies.

DaveL

Programmer
Jun 8, 2000
40
US
How do I update the current record while looping through a SCAN / ENDSCAN?

Code:
select * from filea
SCAN
   update filea.field1 = 999
ENDSCAN

Thanks!
 
SELECT filea
SCAN
*//update filea.field1 = 999
REPLACE field1 WITH "999" && In case the field is char
REPLACE field1 WITH 999 && In case the field is NUM
ENDSCAN

Walid Magd
Engwam@Hotmail.com
 
Why not use ...
REPLACE ALL field1 WITH myValue FOR myConditions ramani :-9
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
 
DaveL

An alternative to SCAN...ENDSCAN, assuming all you want to do is to replace fields with a value

REPLACE filea.field1 [scope] WITH = 999 [FOR expr] [WHILE lExpr]
or
REPLACE filea.field1 [scope] WITH = "999" [FOR expr] [While lExpr]

Chris :)
 
Thanks for the input. Here is a little more information on what I am trying to do.

I am trying to assign an ID Number to each record in the file (mwdv_test) that has an ID Number = 0. I want to retrieve the ID Number from a Next Number Table (next_nbr) and use that to increment to ID Number. Following is the actual code:

Code:
** Assign Id Number from Next Number Table If Id Number = 0
use next_nbr in 2
SELECT 2
LOCATE   
select * from mwdv_test where mwd_id_num = 0 
SCAN
   mwd_id_num_tmp = next_nbr.mwdv_no
   REPLACE next_nbr.mwdv_no WITH next_nbr.mwdv_no + 1 in 2
   replace mwdv_test.mwd_id_num with mwd_id_num_tmp 
ENDSCAN

Only the last record in the mwdv_test file is being updated??

 
Hi Dave,

You aren't scanning mwdv_test. Your statement

select * from mwdv_test where mwd_id_num = 0

yields a cursor of records selected from mwdv_test and it's this cursor that you're scanning. Try:

select mwdv_test
scan for mwd_id_num = 0
.......


Jim
 
We got it! Following is the code that works:

Code:
** Assign Id Number from Next Number Table If Id Number = 0
use mwdv_test in 1
use next_nbr in 2
SELECT 2
LOCATE   
select 1
SCAN for mwd_id_num = 0
   mwd_id_num_tmp = next_nbr.mwdv_no
   REPLACE next_nbr.mwdv_no WITH next_nbr.mwdv_no + 1 in 2
   replace mwdv_test.mwd_id_num with mwd_id_num_tmp 
ENDSCAN

Thanks to all for your feedback!!!

Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top