Randy, Another little tip to make life easier. Let the cursor combine first and last names DECLARE c1 CURSOR FOR SELECT teacherno, (tfirstname & tlastname) + FROM teacher + WHERE teacherno IN + (SELECT teacherno + FROM pdperson)
OPEN c1 FETCH c1 INTO + vteacherno INDICATOR ivvar1 + vteachername INDICATOR ivvar2 This way you can simplify SET items in the loop. Jim Bentley American Celiac Society [email protected] tel: 1-504-737-3293 ________________________________ From: "[email protected]" <[email protected]> To: RBASE-L Mailing List <[email protected]> Sent: Thursday, June 11, 2009 5:48:22 PM Subject: [RBASE-L] - Re: Cursor operation continues after end of data I almost changed the Subject to: It's been a WHILE. Thank you so much to Marc, Emmitt, and Karen for the Sudden response. I could not cut and paste the responses faster than they were coming in. I kind of remembered that I shouldn't use a GOTO to exit, and I was frustrated that it continued after the data ended, wasted paper, had to be closed while operating and so forth. Thank you also for the tutorials and suggestions to help me understand so the next time I can be more successful on my own. Then I will try for a loop within a loop...A loop the loop. I took the pattern for the Cursor from the R:Base editor, but it has been a while. Best R:egards and thanks again to all. Randy Peterson -------- Original Message -------- Subject: [RBASE-L] - Re: Cursor operation continues after end of data From: "MDRD" <[email protected]> Date: Thu, June 11, 2009 5:06 pm To: [email protected] (RBASE-L Mailing List) Randy >From the help file, I had to look it up too ...LOL Exiting from a WHILE Loop To exit from a WHILE loop before the WHILE condition becomes false, use an IF...ENDIF structure to check other conditions, then use BREAK to exit from the WHILE loop. The BREAK command causes the WHILE loop to terminate when the conditions specified in the IF statement become true. Never use GOTO to exit from a WHILE loop; use BREAK instead. BREAK clears the WHILE loop. When you do not use BREAK or the naturally occurring exit (that is, when the WHILE loop conditions are no longer true) to exit from a WHILE loop, R:BASE continues to read commands into memory. If you have a large command or procedure file, you can run out of memory and your program terminates abnormally. Marc From: MDRD Sent: Thursday, June 11, 2009 4:45 PM To: RBASE-L Mailing List Subject: [RBASE-L] - Re: Cursor operation continues after end of data Randy try Break like this IF SQLCODE = 100 THEN BREAK ENDIF Marc From: [email protected] Sent: Thursday, June 11, 2009 4: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

