Randy,
Try moving the FETCH to just before the ENDWHILE, then put the SET VAR and SELECT … FROM just after the WHILE. That also lets you remove the SET VAR and SELECT before the WHILE. What’s happening is that your SELECT .. FROM pdperson is succeeding, setting SQLCODE to 0. Emmitt Dove Manager, Converting Applications Development Evergreen Packaging, Inc. [email protected] (203) 214-5683 m (203) 643-8022 o (203) 643-8086 f [email protected] From: [email protected] [mailto:[email protected]] On Behalf Of [email protected] Sent: Thursday, June 11, 2009 5:23 PM To: RBASE-L Mailing List Subject: [RBASE-L] - Cursor operation continues after end of data I have a cursor operation that prints a report for a list of people. It is so enthusiastic that it continues to print after the end of data is reached. Unfortunately it duplicates the final report and seems to be in an endless loop which requires an inelegant exit from the program. When I traced the operation I can confirm that the value for SQLCODE changes so that it is no longer 100. That should interrupt the: WHILE SQLCODE <> 100 THEN Thinking that I might not have been talking loud enough, I reminded the program again that 100 was reached with the following command, which was also ignored: IF SQLCODE = 100 THEN GOTO lfinish ENDIF ENDWHILE LABEL lfinish and so forth. Sometimes I figure out what is not working while I attempt to document it for someone else. Not this time... Can you suggest how I can help the operation to stop when it is complete. Best R:egards, Randy Peterson -------------------------------------- PRNSETUP 'LEXMARK C544 XL' SET ERROR MESSAGE 705 OFF DROP CURSOR c1 SET ERROR MESSAGE 705 ON DECLARE c1 CURSOR FOR SELECT teacherno, tfirstname, tlastname + FROM teacher + WHERE teacherno IN + (SELECT teacherno + FROM pdperson) --FROM vwTeacherNo) OPEN c1 FETCH c1 INTO + vteacherno INDICATOR ivvar1 + vtfirstname INDICATOR ivvar2 + vtlastname INDICATOR ivvar3 CLEAR VAR vteachername CLEAR VAR vpdevents SET VAR vteachername = (.vtfirstname & .vtlastname) SELECT pdevents INTO vpdevents FROM pdperson + WHERE teacherno = .vteacherno WHILE SQLCODE <> 100 THEN PRINT pdteacher + WHERE (CTXT(pdid)) IN (&vpdevents) OPTION PRINTER FETCH c1 INTO + vteacherno INDICATOR ivvar1 + vtfirstname INDICATOR ivvar2 + vtlastname INDICATOR ivvar3 SET VAR vteachername = (.vtfirstname & .vtlastname) SELECT pdevents INTO vpdevents FROM pdperson + WHERE teacherno = .vteacherno IF SQLCODE = 100 THEN GOTO lfinish ENDIF ENDWHILE LABEL lfinish DROP CURSOR c1 --DROP VIEW vwTeacherNo CLEAR VAR vteachername CLEAR VAR vpdevents RETURN

