JM:

If I understand correctly, you are updating the same column more than once
each iteration of the loop, i.e. you update the column do some more checking
and the update again. I would suggest that you keep the value that you want
for the column as a variable and, after you have done all the checking, you
do only one update. Something like this:

--- set initial value
SET VAR vtemp = 0
DECLARE c2 CURSOR FOR SELECT numcde FROM T2commande WHERE cerreur IS NULL
OPEN c2
WHILE #PI <> 0 THEN
   FETCH c2 INTO vnumcde
   IF SQLCODE = 100 THEN
      BREAK
   ENDIF
IF (some condition) THEN
      SET VAR vtemp = 1
ENDIF
IF (some other condition) THEN
      SET VAR vtemp = 2
ENDIF
IF (a third condition) THEN
      SET VAR vtemp = 3
ENDIF
UPDATE T2commande SET cerreur = .vtemp WHERE CURRENT OF C2
ENDWHILE

I normally use primary keys, which I retrieve in the FETCH statement and I
use them to specify the row, rather than use the "WHERE CURRENT OF CURSOR"
command. With this approach you can have as many updates as you want; also,
if you have the same primary key in another table, you can update data on
that table as well.

SET VAR vtemp = 0
DECLARE c2 CURSOR FOR SELECT numcde, primary_key FROM T2commande WHERE
cerreur IS NULL
OPEN c2
WHILE #PI <> 0 THEN
   FETCH c2 INTO vnumcde, vprim_key
   IF SQLCODE = 100 THEN
      BREAK
   ENDIF
IF (some condition) THEN
      SET VAR vtemp = 1
ENDIF
IF (some other condition) THEN
      SET VAR vtemp = 2
ENDIF
IF (a third condition) THEN
      SET VAR vtemp = 3
ENDIF
UPDATE T2commande SET cerreur = .vtemp WHERE primary_key = .vprim_key
UPDFATE another_table SET another_column = .some variable WHERE
another_primary_key = .vprim_key
ENDWHILE

Javier,

Javier Valencia, PE
President
Valencia Technology Group, L.L.C.
14315 S. Twilight Ln, Suite #14
Olathe, Kansas 66962-4578
Office (913)829-0888
Fax (913)649-2904
Cell (913)915-3137

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of J.M. GRATIAS
Sent: Wednesday, June 04, 2003 6:25 AM
To: RBASE-L Mailing List
Subject: [RBASE-L] - Issue with CURSOR in RBW6.5++


Hi all,


Is there any rules that prevent from using severals UPDATE on the same row
in a DECLARE CURSOR/WHILE LOOP ?

I am supprise that, in the following command file, the fisrt UPDATE works
correctly, but the second one return error 2378
'Cursor is not positionned on a valid row'.

Any idea ?

Using W98SE and RBW 6.5++ build 1.851xRT03 ...


DECLARE c2 CURSOR FOR SELECT numcde FROM T2commande WHERE cerreur IS NULL
OPEN c2

WHILE #PI <> 0 THEN
   FETCH c2 INTO vnumcde
   IF SQLCODE = 100 THEN
      BREAK
   ENDIF
   .........
   UPDATE T2commande SET cerreur = 99 WHERE CURRENT OF C2
   ........
   SET RULES ON
   UPDATE T2commande SET cerreur = NULL WHERE CURRENT OF C2
   ......
ENDWHILE

J.M. GRATIAS, Logimatique

Reply via email to