Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# CR 8.5:  Limit on the number of times a loop can run?

Posted on 2006-11-09
Medium Priority
1,382 Views
i have a section of code that works just fine if i forcefully limit the loops.  if i let the code run without forcefully limiting the loop, i get an error:
"A loop was evaluated more than the maximum number of times allowed"

when i do not try to forcefully limit the loop, the loop is attempting to run about 800 times.  is there a limit on the number of times a loop can run?  and if so, what is that limit?

here is the code:
local numberVar qm9size:=ubound(qm9Array1);

//   qm9size:=3;  //forcefully limit the loop  *****************  THE PROBLEM IS HERE *********************
for cnt2:=1 to qm9size do
(
if split(qm9Array1[cnt2],",")[1]=t then
(
savecnt:=cnt2;
qm9qty:=cdbl(split(qm9Array1[cnt2],",")[2]);
t2:=split(qm9Array1[cnt2],",")[1];
if qm9qty=0 then qm9qty:=-999;
)
);

so if i don't set qm9size manually, it is about 800 and the error happens.
0
Question by:zephyr_hex (Megan)
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 7
• 6
• 2

LVL 7

Expert Comment

ID: 17907942
0

LVL 7

Expert Comment

ID: 17907948
0

LVL 44

Author Comment

ID: 17908065
any ideas on why i'm getting the error then?
i am pretty sure i'm hitting about 800 loops.  i checked by printing out the value of qm9size.  it is 752.
0

LVL 44

Author Comment

ID: 17908148
i have manually set qm9size to 752.

i get the error.

so i kept setting the value to a lower and lower number until it would run without error.  it worked at 199, so i started incrementing up to see how far up i could go before the error returns...
it works at 220 and fails at 221

:(
0

LVL 7

Expert Comment

ID: 17908186
Is that the whole formula?
0

LVL 44

Author Comment

ID: 17908390
no, but i'm 99.9% sure it is the section of the formula that is causing the problem.  when i comment that section out, the report runs fine.  when i limit the qm9size to something under 221, the report runs fine.

here is the complete code for this formula:
whileprintingrecords;
shared stringVar array qm1Array1;
shared stringVar array qm9Array1;
local numberVar qm1qty;
local numberVar qm9qty;
local numberVar qm1size:=ubound(qm1Array1);
local numberVar qm9size:=ubound(qm9Array1);
local numberVar cnt;
local numberVar cnt2;
local numberVar cnt3:=1;
local numberVar result;
local stringVar all_results;
local stringVar t;
local stringVar t2;
global stringVar showqm1;
global stringVar showqm12;
global stringVar showqm13;
global stringVar showqm14;
local numberVar cnt4;
local stringVar v;
local numberVar savecnt:=0;
local numberVar tmpy:=0;

if ubound(qm1Array1)>0 then
(

for cnt:=1 to qm1size do
(
if {Whses.Whse}="000" then
(

t:=split(qm1Array1[cnt],",")[1];
qm1qty:=cdbl(split(qm1Array1[cnt],",")[2]);
qm9qty:=-999;  //default
tmpy:=qm9size;
qm9size:=220;  //test  *****************  THE PROBLEM IS HERE *********************
for cnt2:=1 to qm9size do
(
if split(qm9Array1[cnt2],",")[1]=t then
(
savecnt:=cnt2;
qm9qty:=cdbl(split(qm9Array1[cnt2],",")[2]);
t2:=split(qm9Array1[cnt2],",")[1];
if qm9qty=0 then qm9qty:=-999;
)
);

if not(qm9qty=-999) then
(
result:=(qm9qty-qm1qty);   // this is how many are left in FD

if result<0 then
(

qm9Array1[savecnt]:=t&","&((qm1qty-abs(result))-qm9qty);  // put new result into array

showqm1:=(showqm1 & t & pad & cstr(qm1qty-abs(result)) & chr(13))
) else if result>=1 then  // don't report if result = 0 or less than 1
(
result:=qm1qty;   //all of them are transferred
showqm1:=(showqm1 & t & pad & cstr(result) & chr(13))
(
showqm12:=(showqm12 & t & pad & cstr(result) & chr(13))
)
showqm13:=(showqm13 & t & pad & cstr(result) & chr(13))
else
showqm13:="Out of array space";

qm9Array1[savecnt]:=t&","&(qm9qty-qm1qty);  //take them out of FD

)
);

) else all_results:="none,0";

);

);
tmpy;
0

LVL 7

Expert Comment

ID: 17908667
How big is qm1size?  You do have a nested loop.  So, we'd have to multiple them to figure out how many loops you are doing.  Also, are you using the result of this formula in another formula where you do another loop?  Or, is one of the input variables to this formula looped through before supplying it to this formula?
0

LVL 44

Author Comment

ID: 17908953
qm1size is 135.  i totally missed the nested loop.

i am not using the result of this formula in another loop.  the result of this formula gets displayed.  (the showqm1 array is called in another formula only for the purposes of printing).

i checked the subreport that gets run just prior to this particular formula, and there are no loops.

but... i have a total of 4 subreports, and each subreport has a formula after it which is similar to the one above.  so the report, in total, has 4 formulas that are pretty much identical to the one above.

is the loop count per formula, or per report?
0

LVL 7

Accepted Solution

ast2550 earned 2000 total points
ID: 17909032
135 * 221 = 29835 which is darn near the 30,000 limit, for cr8.

By Formula, but...I dodn't know how that would work if there were several formulas passing values that each looped.

30,000 sounds like it is the reason.

0

LVL 44

Author Comment

ID: 17909419
ok.
i will have to try breaking the loops up, or perhaps breaking up the arrays so they are smaller.

thanks
0

LVL 101

Expert Comment

ID: 17912164
Where is the formula in the report?  If it is a detail section formula it is running once for each record int he recordset.

mlmcc
0

LVL 7

Expert Comment

ID: 17914207
mlmcc, so are you saying that the formula loop limit also considers the number of records...
records * loop * nested loop < 30,0000

I'd think the reason for the limit was to prevent an endless loop...which wouldn't really apply to the whole recordset.
0

LVL 101

Expert Comment

ID: 17919804
I don't know.  I didn't realize there there was a limit.

I was pointing out that the loop would run for each record and thus might have an impact on performance.

mlmcc
0

LVL 44

Author Comment

ID: 17951072
it is not in the details sections.

it is in the Group Header.
0

LVL 44

Author Comment

ID: 17957370
here is a pic of the report structure:
http://img20.imageshack.us/my.php?image=exik8.jpg

i haven't had the chance yet to split up the loops.  i am waiting for the user to decrease the total number of items (records) that will get run because right now this report is going to run like 700 pages.  when i run the report on a smaller number of items, there are fewer loops because fewer items meet the criteria for looping, and the report runs ok.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirementsâ€¦
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearlyâ€¦
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can reâ€¦
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for â€¦
###### Suggested Courses
Course of the Month4 days, 10 hours left to enroll