Coop
New Member
Any help would be greatly appreciated.I would not describe it that way.
PRESELECT makes a snapshot of the result set at the point in time that it is first invoked. To access the records in the snapshot you use FIND.
How it does that behind the scenes is not the point of my comments.
I am grappling with this PRESELECT statement. Never understood or trusted it. I have done this several times over the years and I am trying to find a better way.
I need to duplicate a set of recs to the same table so:
rec.fld1 is the only index in this particular case.
Example:
Code:
def buffer brec for rec.
for each rec no-lock where rec.fld1 = "xyz" and rec.fld2 = "xyz":
buffer-copy rec to brec.
assign brec.fld1 = "abc"
brec.fld2 = "abc".
end.
Am I missing something? Obviously I am but is there a way?? Without having to loop through and gather the rowids and loop through those in a separate loop?
Actual code I used to test:
Record is deleted at top and created in the loop when i=5.
I comment/uncomment the "for each/preselect" code.
zcomp.measid is the only index.
Code:
def var i as int no-undo.
def buffer bzcomp for zcomp.
for each zcomp where zcomp.char2 = 'div12'
and zcomp.measid= 'zzz'.
disp 'delete loop' zcomp.char2 zcomp.measid.
delete zcomp.
end.
/*
REPEAT PRESELECT EACH zcomp where zcomp.char2 = 'div12' no-lock:
find next zcomp.
*/
FOR EACH zcomp where zcomp.char2 = 'div12' no-lock:
i = i + 1.
disp 'LOOP1'
trim(string(i,'>>>')) label 'cnt'
zcomp.char2
zcomp.measid.
if i=5 then do:
create bzcomp.
assign bzcomp.char2='div12'
bzcomp.measid='zzz'.
end.
end.
i = 0.
for each zcomp where zcomp.char2 = 'div12' no-lock:
i = i + 1.
disp 'LOOP2'
trim(string(i,'>>>')) label 'cnt'
zcomp.char2
zcomp.measid.
end.
Last edited by a moderator: