Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1391
  • Last Modified:

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

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
zephyr_hex (Megan)
Asked:
zephyr_hex (Megan)
  • 7
  • 6
  • 2
1 Solution
 
ast2550Commented:
0
 
zephyr_hex (Megan)DeveloperAuthor Commented:
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
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
zephyr_hex (Megan)DeveloperAuthor Commented:
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
 
ast2550Commented:
Is that the whole formula?
0
 
zephyr_hex (Megan)DeveloperAuthor Commented:
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
 
ast2550Commented:
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
 
zephyr_hex (Megan)DeveloperAuthor Commented:
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
 
ast2550Commented:
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
 
zephyr_hex (Megan)DeveloperAuthor Commented:
ok.
i will have to try breaking the loops up, or perhaps breaking up the arrays so they are smaller.

thanks
0
 
mlmccCommented:
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
 
ast2550Commented:
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
 
mlmccCommented:
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
 
zephyr_hex (Megan)DeveloperAuthor Commented:
it is not in the details sections.

it is in the Group Header.
0
 
zephyr_hex (Megan)DeveloperAuthor Commented:
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 7
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now