Buddy et. al.,
One comment I would make on this structure is that it will eat memory in a hurry if there are any significant number of iterations on C1. I've found the following outline to be advisable:
Declare c1
Declare c2
Open c1
Fetch c1
While .... (c1)
(do stuff)
Open c2 RESET
Fetch c2
While .... (c2)
(do stuff)
Fetch c2
Test SQLCODE
Endwhile (c2)
Close c2
Fetch c1
Test SQLCODE
Endwhile (c1)
Drop c1
Drop c2
Using the OPEN ... RESET feature saves processing time by not having to declare the inner cursor for every iteration of the outer, and is far more memory-efficient. The only trick is that if the inner cursor is based on variables you must establish and type the variables before declaring the cursor. When you do the OPEN ... RESET R:Base will evaluate the variables at that time and retrieve the desired records.
One final comment is that I will use IF/ENDIF and LABELs with GOTOs rather than a WHILE/ENDWHILE. Given the speed of today's computers there is no appreciable speed penalty to not using optimized WHILE loops, and I can avoid the pitfalls they present.
Steve
You could set your cursor while loops as
Make sure your SET/DEFINE all our variables outside the while loops.
SET VAR VIdNumber INTEGER
SET VAR VLastName TEXT
DROP CURSOR C1
DECL C1 CURSOR FOR SEL idnumber FROM sometable
OPE C1
--While for c1
WHILE 1 = 1 THEN
FETCH C1 INTO Vidnumber INDIC IVIdnumber
IF SQLCODE = 100 THEN
BREAK
ENDIF
DROP CURSOR C2
DECL C2 CURSOR FOR SEL columnlist FROM sometable whe idnumber =
.vidnumber
OPE C2
--While for c2
WHILE 2 = 2 THEN
FETCH C2 INTO ....
IF SQLCODE = 100 THEN
BREAK
ENDIF
--EndWhile for c2
ENDWHILE
DROP CURSOR C2
--EndWhile for c1
ENDWHILE
DROP CURSOR C1
Manager, DairyPak Business Systems
Blue Ridge Paper Products, Inc.
40 Lindeman Drive
Trumbull, CT 06611
(203) 673-2231
[EMAIL PROTECTED]
[EMAIL PROTECTED]
