Larry: Thanks for the detailed response. I think your looping approach beats my standard looping approach. But!

In this particular application, I'm generating (potentially) millions of records, so speed is paramount. My musing anticipates that a cursor beats any loop hands down: I stand to be disabused of this notion.

So I suppose what I'm thinking of is a NEW syntax, an enhancement suggestion for the Dr:eam Team:

DECLARE Cursor0 CURSOR FOR +
SELECT HumptyID FROM Humpty ORDER BY HumptyID

WHILE ...

   DECLARE Cursor1 CURSOR FOR ARRAY(1,5,1,)
   <useful code here>

...

Thanks again,

Bruce Chitiea
SafeSectors, Inc.
909.238.9012 Mobile

------ Original Message ------
Sent: 2/17/2017 5:15:12 AM
Subject: Re: [RBASE-L] - DECLARE CURSOR Source Data Array
From: "'Lawrence Lustig' via RBASE-L" <[email protected]>
To: "[email protected]" <[email protected]>
Cc:

<<
Is there an "elegant" way to do this with a simple array of values:


DECLARE CursorName CURSOR FOR (1,2,3,4,5)
... where we're stepping through the array WITHOUT drawing upon a source table?
>>

Is this expected to produce five iterations with one value each time, or one iteration with five values?

If you want five iterations of the loop with one value each time, and the values are guaranteed not to contain commas (which will be true if they're numeric values) then you can do this:

SET VAR tList TEXT = ('1,2,3,4,5')
SET VAR tIndex INT = 0

WHILE 1 = 1 THEN

    SET VAR tIndex = (.tIndex + 1)
    SET VAR tTextTerm = (SSUB(.tList, .tIndex))
    IF tTextTerm IS NULL THEN
       BREAK
    ENDIF

    -- Cast to appropriate type if not TEXT
    SET VAR tIntTerm INT = (INT(.tTextTerm))

    -- Meaningful code here

ENDWHILE

CLEAR VAR tList, tIndex, tTextTerm, tIntTerm
RETURN

You can construct more complex scenarios by pulling two or three terms off the list for each iteration, or using a different character to separate fields and records in the list. This is also suitable for use with LISTOF(), getting a list of values from a table and then iterating over the list without the cursor.
--
Larry

--
You received this message because you are subscribed to the Google Groups "RBASE-L" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups 
"RBASE-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to