----- Original Message -----
From: David Blocker <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Monday, April 30, 2001 11:29 AM
Subject: Re(2): While loop problem

David,


In the below examples, "Not this" is not an infinite loop, as it will self
terminate after the last row.  Breaking out of a true  infinite loop, such
as WHILE #pi>0,  with IF-BREAK-ENDIF makes total sense. Are there any other
reasons that you prefer #2? Is there a difference in efficiency between the
two when working on large tables?


Thanks,

Terry



> 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
>
>



Reply via email to