I would avoid the goto inside the while loop. It is rather easy to achieve.
Use BREAK to exit the WHILE loop. This is the correct way to do this.
DECLARE C1 CURSOR FOR SEL DISTINCT Cust FROM AuditCharge
OPEN C1 RESET
SET V vTest INT=NULL
WHILE vTest IS NULL THEN
FETCH C1 INTO vCust IND v1
IF SQLCODE = 100 THEN
BREAK
ENDI
WRI .vCust AT 22 29
SEL SUM (SubTot+TaxAmt) INTO vUnPd IND v1 FROM ApplyPay +
WHERE Cust = .vCust
SEL SUM (PaymentAmt-PaymentUsed) INTO vUaPay IND v1 FROM ApplyPay +
WHERE MethType IN (240 242 250) AND Cust = .vCust
SET V vCurBal = (.vUnPd-.vUaPay)
UPDATE Cust SET CurBal = .vCurBal WHERE Cust = .vCust
ENDW
CLOSE C1
DROP CURSOR C1
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
Behalf Of Frank Radice
Sent: Friday, April 27, 2001 6:08 PM
To: RBASE mailing list (E-mail)
Subject: While loop problem
I have a client that has the following code:
DECLARE C1 CURSOR FOR SEL DISTINCT Cust FROM AuditCharge
OPEN C1 RESET
SET V vTest INT=NULL
WHILE vTest IS NULL THEN
FETCH C1 INTO vCust IND v1
IF SQLCODE = 100 THEN
SET V vTest = 1
GOTO ALLDONE
ENDI
WRI .vCust AT 22 29
SEL SUM (SubTot+TaxAmt) INTO vUnPd IND v1 FROM ApplyPay WHERE Cust =
.vCust
SEL SUM (PaymentAmt-PaymentUsed) INTO vUaPay IND v1 FROM ApplyPay WHERE
MethType IN (240 242 250) +
AND Cust = .vCust
SET V vCurBal = (.vUnPd-.vUaPay)
UPDATE Cust SET CurBal = .vCurBal WHERE Cust = .vCust
LABEL ALLDONE
ENDW
CLOSE C1
DROP CURSOR C1
Everything runs OK most of the time, but every so often, the program stops
with the error message "-Error- GOTO cannot jump into SWITCH or WHILE
blocks. (686).
It always goes thru the while loop correctly for all Cust (Cust gets updated
correctly for ALL Cust in the DECLARE) so it appears to be the GOTO ALLDONE
not being able to find the LABEL ALLDONE. I have suggested that they
replace the GOTO code with BREAK in the IF...THEN. However, I can't figure
out why this code works 98% of the time and fails the other 2% of the time.
They have WHILEOPT set OFF.
Any thoughts??