Terry -

He wasn't missing a second Fetch - it is fine - in fact I think preferable
to have only ONE FETCH inside an infinite loop with a BREAK to get out.

Not this:

DRO CUR C1
DECLARE C1 CURSOR FOR  SEL DISTINCT Cust FROM AuditCharge
OPEN C1
FETCH C1 INTO vcust vicust
WHILE SQLCODE <> 0 THEN
         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
        FETCH C1 INTO vcust vicust
ENDIF
DRO CUR C1

But this:

DRO CUR C1
DECLARE C1 CURSOR FOR  SEL DISTINCT Cust FROM AuditCharge
OPEN C1
WHILE #PI <> 0 THEN
       FETCH C1 INTO vcust IND vI1, vicust IND vI2
       IF SQLCODE = 100 THEN
          BREAK
       ENDIF
            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
        ENDIF
DRO CUR C1


As to the original question, is there another LABEL ALLDONE anywhere else
in the code?  And are the variables used in the loop preset outside the
loop?  The BREAK solution IS the best and cleanest way to do it.
David Blocker

Reply via email to