Karen

I would take this cursor you are trying to eliminate is the outer one.

 

  I would create a temporary table and load all of the values from the
autonumber field that meets your where clause.

 

  Your code would replace the outer curse with something like this (Notice
commented out the while loop)

 

Buddy

 

    SET VAR vMyAutoNumber INTEGER = 0

    SET VAR vRows INTEGER = 0

 

--While SQLCODE <> 100 THEN

    LABEL StartWhileC1Here

     SET VAR vMyAutoNumber = 0

     SELECT autonumerField INTO vMyAutoNumber INDICATOR iv1 FROM tempTable
WHERE LIMIT = 1

     IF vMyAutoNumber = 0 THEN

       GOTO Done

     ENDIF

 

      Run your other code here 

       Then any place you want to jump to the end just 

--Make sure if you break out of anywhere loops make sure to close any open
cursor.

 

      GOTO EndWHileC1Here 

        

      

 

    LABEL EndWhileC1Here

    DEL ROW FROM TempTable WHERE AutonumberFiled = .vMyAutoNumber 

    SELECT COUNT(*) FROM INTO vRows INDIC IV FROM TempTable WHERE COUNT = 1

    IF vRows <> 0 THEN

      GOTO StartWhileC1Here

    ELSE

    GOTO Done

    ENDIF

--ENDWHILE

 

   LABEL Done

 

From: [email protected] [mailto:[email protected]] On Behalf Of
[email protected]
Sent: Tuesday, September 11, 2012 6: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