Karen,

 

It is clear what your problem was.

I have had similar problems too in the past.

 

What I mean with the IF statement is:

Every IF statement has 2 results.

2 IF statements means that there are 4 possible ways to go through your program

N IF statements will have 2 to the power of N possible ways to go through your 
program.

 

Although I am aware it is a little hypotatical (correct word?), lots of IF 
statements will make the program very complex and sometimes hard to understand 
what is happening in the code. Especially when you have not looked into it for 
a while.

On the other hand they are necessary and it is impossible to avoid them. 

 

Generally speaking the combination of IF and GOTO are not advisable, because 
then it is easy to create a very complex structure or even an endless loop.

 

I am aware this a bit theoretical discussion. 

But one of my favorit sayings is: Theory without practice  is for the genious 
and practice without theory is for the idiots.

 

Have a nice weeekend

 

Tony

 

From: [email protected] [mailto:[email protected]] On Behalf Of Karen Tellef
Sent: vrijdag 21 maart 2014 13:58
To: RBASE-L Mailing List
Subject: [RBASE-L] - Re: Thanks to someone for the code!

 

Tony:  It originally was a typical while/endwhile statement.  However,
it would never get through all 37K rows.  It would randomly lock up,
never the same record, just randomly somewhere after processing
the first 1000 rows or so.  Never having seen a cursor process that
many rows before (it's a DOS program written by someone else, I'm
bringing it to windows) I figure it was a case of the "while" loop, even
though I run with whileopt off.    I posted here, and several people
recommended that instead of the while loop that I instead use a
goto/label construct.   So far I've tested it a half dozen times on 
different sets of records of between 30K and 40K rows and so far
it's rock solid!

I'm sorry, I don't understand your statement about the "if statements".
Could you explain?   I'd have to count since there's hundreds of lines
of code for each row processed, I'll get I have dozens of "if" statements
in there.

Karen

 

 

-----Original Message-----
From: Tony IJntema <[email protected]>
To: RBASE-L Mailing List <[email protected]>
Sent: Fri, Mar 21, 2014 6:41 am
Subject: [RBASE-L] - Re: Thanks to someone for the code!

Karen,

 

Maybe not relevant, but why don’t you use the while-endwhile construction.

If statements are handy, but also a little dangerous

10 if statements in a program will result in 1024 paths through your program

 

Tony

 

DROP CURSOR c1
DECLARE c1 CURSOR FOR SELECT  ....... blah blah blah
OPEN c1
FETCH c1 INTO ..... blah blah blah
while SQLCODE <>  100 THEN
       -- do all your processing here

FETCH c1 INTO ..... blah blah blah
endwhile
WRITE 'I AM DONE!'

 

From: [email protected] [mailto:[email protected] <mailto:[email protected]?> ] 
On Behalf Of Karen Tellef
Sent: donderdag 20 maart 2014 23:18
To: RBASE-L Mailing List
Subject: [RBASE-L] - Re: Thanks to someone for the code!

 

Well then, I'm guessing it was either Dennis or Alastair!  Or both!

Karen

 

 

 

-----Original Message-----
From: Alastair Burr <[email protected]>
To: RBASE-L Mailing List <[email protected]>
Sent: Thu, Mar 20, 2014 2:21 pm
Subject: [RBASE-L] - RE: Thanks to someone for the code!

And I, for one, have been using it for many of those years.

 

Cheers, Dennis,

Regards,

Alastair.

 

From: Dennis McGrath <mailto:[email protected]>  

Sent: Thursday, March 20, 2014 7:01 PM

To: RBASE-L Mailing List <mailto:[email protected]>  

Subject: [RBASE-L] - RE: Thanks to someone for the code!

 

Perhaps someone else shared that with you but I’m been preaching that style for 
mucho many years.

 

Dennis McGrath

Software Developer

QMI Security Solutions

1661 Glenlake Ave

Itasca IL 60143

630-980-8461

[email protected]

From: [email protected] [mailto:[email protected] <mailto:[email protected]?> ] 
On Behalf Of Karen Tellef
Sent: Thursday, March 20, 2014 1:52 PM
To: RBASE-L Mailing List
Subject: [RBASE-L] - Thanks to someone for the code!

 

Probably a year ago I asked for recommendations of how to use alternative code 
for a cursor that had to go through 50,000 rows of data, run hundreds of lines 
of code per record, and would periodically lock up.  I got a couple examples, 
and I picked this one as being the easiest to follow, the simplest and best of 
all, IT WORKS!   I forgot who gave it to me, but thank you!   And perhaps this 
will help someone else.

Karen

DROP CURSOR c1
DECLARE c1 CURSOR FOR SELECT  ....... blah blah blah
OPEN c1

LABEL GetCursor

FETCH c1 INTO ..... blah blah blah

IF SQLCODE = 100 THEN
  GOTO EndCursor  
ENDIF

-- do all your processing here

GOTO GetCursor


LABEL EndCursor
WRITE 'I AM DONE!'


RETURN

Reply via email to