Karen,

Here is a sample of how I do goto loops with cursors.

RSTYLE uses the --INDENT and  --OUTDENT comments to maintain readability.

    SET ERROR MESSAGE 705 OFF
    DROP CUR GetBOM
    SET ERROR MESSAGE 705 ON

    DECLARE GetBOM CURSOR FOR SELECT UsedQpart#, UsedQuantity, UsedCutLngth +
        FROM TempBOM WHERE TransID = .vGridTransID AND Window = .vWindow
    OPEN GetBOM

    LABEL LoopBOM
    --INDENT
        FETCH GetBOM INTO vPart, vPartQty, vPartLength
        IF SQLCODE = 100 THEN
            GOTO EndBOM
        ENDIF

       --Code here


    --OUTDENT
    GOTO LoopBOM
    LABEL EndBOM

   DROP CUR GetBOM


Dennis McGrath
Software Developer
QMI Security Solutions
1661 Glenlake Ave
Itasca IL 60143
630-980-8461
[email protected]
From: [email protected] [mailto:[email protected]] On Behalf Of 
[email protected]
Sent: Tuesday, September 11, 2012 5:25 PM
To: RBASE-L Mailing List
Subject: [RBASE-L] - Cursor ideas

Remember a while ago I was asking for ideas about a gigantic cursor that would 
error out at some point.   Probably within a month I'll need to start work on 
this.  

The most popular suggestion was to replace the cursor loops with a bunch of 
"goto".  I've never used Goto for big processes like this, just simple program 
movements.   My first cursor (the biggest one) is through a table with over 
100,000 rows, but the cursor has a where clause so it steps through about half 
of them.   There is an autonumbered column in the table.  

So trying to avoid a "while" loop of any kind, how could I structure the "goto" 
code?   Do I grab a minimum/maximum autonumber that my cusor would have gone 
through, increment it by one to see if there's anything to process (in which 
case there will be thousands of autonumbers that I will increment but not 
process; I guess that's okay as long as the program does work).  

My other thought is that I could make a permanent working table and load it 
with the rows that I would have cursored through, put a fresh autonumber column 
on that table and then step through that table.   There are other cursors to 
other tables based on these rows, so I have to also think of ways to convert 
those into non-cursors (or maybe those will be okay as long as I remove the 
upper level one).

Suggestions again?

Karen


Reply via email to