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.
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
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.
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
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
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?
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.
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
Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.
search for maximum