Frank,

If you need to use the DECLARE CURSOR and WHILE commands, 
then, you may need to use the command as following: 

Example: (Using TGRB2000 6.5++, Build 1.840h and higher) 

SET VAR vCust INTEGER = NULL
SET VAR vUnPd CURRENCY = 0.00
SET VAR vUaPay CURRENCY = 0.00
SET VAR vCurBal CURRENCY = 0.00
SET VAR vMsg TEXT = NULL

SET ERROR MESSAGE 705 OFF 
DROP CURSOR c1
SET ERROR MESSAGE 705 ON 

DECLARE c1 CURSOR FOR SELECT DISTINCT(Cust) FROM AuditCharge
OPEN c1
FETCH c1 INTO vCust INDIC IvCust

WHILE SQLCODE <> 100 THEN
  SET VAR vMsg = ('Updating Customer:'&(CTXT(.vCust)))
  CLS
  PAUSE 3 USING .vMsg CAPTION 'Customer Update' AT 16 36

  SELECT SUM(SubTot+TaxAmt) INTO vUnPd INDIC IvUnPd +
  FROM ApplyPay WHERE Cust = .vCust

  SELECT SUM(PaymentAmt-PaymentUsed) INTO vUaPay +
  INDIC IvUaPay FROM ApplyPay WHERE Cust = .vCust +
  AND MethType IN (240,242,250)

  SET VAR vCurBal = (.vUnPd-.vUaPay)

  UPDATE Cust SET CurBal = .vCurBal WHERE Cust = .vCust 

  SET VAR vUnPd = 0.00
  SET VAR vUaPay = 0.00
  SET VAR vCurBal = 0.00

  FETCH c1 INTO vCust INDIC IvCust
ENDWHILE
DROP CURSOR c1
CLEAR ALL VAR or CLEAR ALL VAR EXCEPT .. or whatever ..
CLS
QUIT TO MainMenu.RMD or whatever ...

Adjust the code, column names and tables accordingly. 

Enjoy and make sure to have fun! 

Very Best Regards, 

Razzak. 


At 04:07 PM 4/27/01 -0700, Frank Radice wrote:

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

===================================-============================
Official R:BASE List Server:    mailto:[EMAIL PROTECTED]
RBTI Events/Training:        http://www.rbase2000.com/events
R:DCC Members:               http://www.rbase2000.com/rdcc
================================================================
R:BASE, Oterro & R:Tango are registered trademarks of RBTI.
==================================-=============================

Reply via email to