At 05:45 PM 6/26/2012, Bruce Chitiea wrote:

Is there a test for a cursor defined in memory, along the lines of:

If exists cursor c1 then
   set var vcursorexists = 'yes'
endif


Bruce,

In addition to CHKCUR function, if you always want to DECLARE a cursor, use the
following code to declare a cursor without having to worry about its existence.

-- Example 01
-- Declaring CURSOR
   SET ERROR MESSAGE 705 OFF
   DROP CURSOR c1
   SET ERROR MESSAGE 705 ON
   -- Pre-Define all variables with correct data type for WHILE-ENDWHILE Loop
   SET VAR vVar1 TEXT = NULL
   SET VAR vVar2 INTEGER = NULL
   SET VAR vVar3 CURRENCY = NULL
   -- Now declare the cursor
   DECLARE c1 CURSOR FOR SELECT column1,column2,column3 +
   FROM [tablename] +
   WHERE [clause]
   OPEN c1
   FETCH c1 INTO +
      vVar1 INDIC ivVar1, +
      vVar2 INDIC ivVar2, +
      vVar3 INDIC ivVar3
   WHILE SQLCODE <> 100 THEN
      -- Do what you have to do
         Your code here ...
      -- Reset values from previously declared row
      SET VAR vVar1 = NULL
      SET VAR vVar2 = NULL
      SET VAR vVar3 = NULL
      FETCH c1 INTO +
         vVar1 INDIC ivVar1, +
         vVar2 INDIC ivVar2, +
         vVar3 INDIC ivVar3
   ENDWHILE
   DROP CURSOR c1
   CLEAR VARIABLES iv%

Have fun!

Very Best R:egards,

Razzak

Reply via email to