Doug
 
YOur code is the logical equivalent of mine - you're looping using GOTO label and we are looping using WHILE / ENDWHILE
 
David Blocker
[EMAIL PROTECTED]
781-784-1919
Fax: 781-784-1860
Cell: 339-206-0261
----- Original Message -----
Sent: Monday, February 07, 2005 11:08 AM
Subject: [RBG7-L] - Re: Fetch command

But David and Larry ("There's no extra checking. In David's method, the WHILE loop becomes an
infinite loop"), doesn't the WHILE loop always have to check the condition, whether it's a moving target like SQLCODE <> 100 or an infinite loop like WHILE 1 = 1.  _We_  know 1 always = 1 and #PI is never equal to 0 and are infinite loops, but the computer doesn't and will dutifully check it through every iteration.  So it seems an IF - ENDIF duplicates the work the WHILE loop is doing and doubles the required processing, granted by probably only a few milli-micro seconds.  If you are going to use an IF- ENDIF, then why even bother with the WHILE loop?  It just replaces a couple of labels in this context and can introduce WHILEOPT considerations (for better or worse).  Hmmm, does WHILEOPT recognize infinite loops?

LABEL StartLoop
Fetch
IF SQLCODE <> 0 THEN
  GOTO EndLoop
ENDI
--Process the Fetch
GOTO StartLoop

LABEL EndLoop

What am _I_ missing?

Having said all that, FWIW, I use WHILE and 2 FETCHES.  After being stung a couple of times by modifying only one of 'em, you remember...

Doug Hamilton

David M. Blocker wrote:
Hi MIke

I assume this was directed at my answer.

Notice my WHILE loop does NOT check for the SQLCode:

My structure was:

DROP cursor
DECLARE cursor
OPEN cursor
WHILE #PI <> 0 THEN
   FETCH
   IF SQLCODE <> 100 THEN
      BREAK
   ENDIF
   --commands for what to do after FETCH
ENDWHILE
DROP cursor

This structure has worked well for me for years.  Am I missing something?

David Blocker
[EMAIL PROTECTED]
781-784-1919
Fax: 781-784-1860
Cell: 339-206-0261
----- Original Message -----
From: "MikeB" <[EMAIL PROTECTED]>
To: "RBG7-L Mailing List" <[email protected]>
Sent: Monday, February 07, 2005 9:50 AM
Subject: [RBG7-L] - Re: Fetch command


  
*(It's inefficient in your coding to have TWO Fetch commands, one inside
      
the
  
loop and one outside
Fetch Rt1 into vProjID INDIC ivPJD, vQT1 INDIC ivQT1, vCODE INDIC
      
ivCODE, +
  
vSTARTDTE INDIC iVSTARTDTE, vENDDTE INDIC ivENDDTE
      
I agree with your changes Except for the theory on the Fetch...

With the first Fetch before the beginning of the While loop, Fetch is
    
called
  
the Exact "number" of times to circumvent the recordset, so the Only thing
    
that
  
is different is writing the Fetch statement Twice in Code.

This is small potatoes compared to the Condition checking in your While
    
Loop.
  
Having the While check for the SqlCode Once per Loop would be more
    
desirable
  
than Checking Twice per Loop in your scenario, Once for the While
    
condition and
  
Once for the If condition...

I understand the desire to use the Fetch only once, because you have
    
reduced
  
the chance for error in the Fetch by Half, but for my money, I'll stick to
    
the
  
old way.

    


  

Reply via email to