Access table in for loop in nested find

kblackwel

New Member
I'm using a for loop with a nested find



for each icsp where icsp.cono = v-cono and icsp.prod = v-prod
exclusive-lock:
find notes where notes.cono = icsp.cono and notes.primarykey = string(icsp.prod) no-error.
if available notes then



My problem is I don't seem to be able to access the icsp table from within the find function.

If I do a


assign icsp.notes = "*"
update notes.notestype = "P"

after the "if available notes then" I get an error or the assign icmp.notes line.


I know it's a scope issue, but not sure how to work around.
 

Stefan

Well-Known Member
0. please use code tags around code.
1. why are you using UPDATE inside a loop that is locking records? This will keep records locked until the user responds.
2. why are you not specifying the LOCK type on FIND notes?
3. which error are you getting?
4. how did you come to he conclusion that it is a scope issue?
5. why do you think you need to work-around scope issues? Scope is not something to work-around, it is something that should be used.

Code:
DEFINE TEMP-TABLE icsp
   FIELD cono  AS INT
   FIELD prod  AS INT
   FIELD notes AS CHAR
   .


DEFINE TEMP-TABLE notes
   FIELD cono        AS INT
   FIELD primarykey  AS CHAR
   FIELD notestype   AS CHAR
   .


DEF VAR v-cono LIKE icsp.cono.
DEF VAR v-prod LIKE icsp.prod.


FOR EACH icsp 
   WHERE icsp.cono = v-cono 
   AND   icsp.prod = v-prod
EXCLUSIVE-LOCK:
   FIND notes 
      WHERE notes.cono        =  icsp.cono 
      AND   notes.primarykey  =  STRING( icsp.prod )
   EXCLUSIVE-LOCK NO-ERROR.
   IF AVAILABLE notes THEN DO:
      icsp.notes = "*".
      UPDATE notes.notestype = "P".
   END.
END.
 
Top