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

Reply via email to