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