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)
RandyFrom the help file, I had to look it up too ...LOLExiting 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.
MarcFrom: MDRDSent: Thursday, June 11, 2009 4:45 PMSubject: [RBASE-L] - Re: Cursor operation continues after end of dataRandytry Break like thisIF SQLCODE = 100 THEN
BREAK
ENDIFMarcFrom: [email protected]Sent: Thursday, June 11, 2009 4:23 PMSubject: [RBASE-L] - Cursor operation continues after end of dataI 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

