Solved

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

Posted on 2006-11-09
15
1,305 Views
Last Modified: 2008-01-09
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
Comment
Question by:zephyr_hex
  • 7
  • 6
  • 2
15 Comments
 
LVL 7

Expert Comment

by:ast2550
ID: 17907942
0
 
LVL 7

Expert Comment

by:ast2550
ID: 17907948
0
 
LVL 42

Author Comment

by:zephyr_hex
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 42

Author Comment

by:zephyr_hex
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

by:ast2550
ID: 17908186
Is that the whole formula?
0
 
LVL 42

Author Comment

by:zephyr_hex
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 stringVar pad;
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];
        if len(t)>len(chr(9)) then pad:=(chr(9)&chr(9)) else pad:=chr(9);   //used below
        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

                if (len(showqm1)+len(pad)+len(t)+len(cstr(qm1qty-abs(result)))+len(chr(13)))<254 then
                    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
                if (len(showqm1)+len(pad)+len(t)+len(cstr(result))+len(chr(13)))<254 then
                    showqm1:=(showqm1 & t & pad & cstr(result) & chr(13))
                else if (len(showqm12)+len(pad)+len(t)+len(cstr(result))+len(chr(13)))<254 then
                (  
                 showqm12:=(showqm12 & t & pad & cstr(result) & chr(13))
                )
                 else if (len(showqm13)+len(pad)+len(t)+len(cstr(result))+len(chr(13)))<254 then
                  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

by:ast2550
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 42

Author Comment

by:zephyr_hex
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

by:
ast2550 earned 500 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 42

Author Comment

by:zephyr_hex
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 100

Expert Comment

by:mlmcc
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

by:ast2550
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 100

Expert Comment

by:mlmcc
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 42

Author Comment

by:zephyr_hex
ID: 17951072
it is not in the details sections.

it is in the Group Header.
0
 
LVL 42

Author Comment

by:zephyr_hex
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now