Easy to Create, Easy to Change - Easy to use!


count of not updated in a while loop


Started by George Washington
Search
You will need to Sign In to be able to add or comment on the forum!

count of not updated in a while loop

Hi there,

I have this simple algorithm to implement:

1. Check how many working days there are between date x and date x - y days (y = 3);

NOTE: I have a special table listing all days till 2050: the day has a field (called FF) with an "F" if it is not a working day, if the FF is blank that day is a working day

2. If the working days are less than 4, increment y, otherwise stop

3. Check again the working days and in case increment y again.

That's should be pretty easy:

j := 3 .

--Counts how many working days between two dates

Wdays := count of Calendar named "tCount1" with day between ( jobs Delivery_date - j ) to jobs Delivery_date AND FF = blank .
while Wdays < 4 do
j := j + 1 .
Wdays := count of Calend named "tCount2" with day between ( jobs Delivery_date - j ) to jobs Delivery_date AND FF = blank .
end

The problem here is that the second "count of" never updates, it returns the same value again and again (I have checked with some message instructions and j is updated, but Wdays has always the same value), it seems that it retains the first result forever.

Could you please advise on this?

Regards

Written by George Washington 16/10/15 at 07:08:04 Dataease [{8}]FIVE

Re:count of not updated in a while loop

Downalod Sample!

This is one of the 20 least well known "bugs" in DataEase, but it is KNOWN ;-)

There has been much debate on this as there is some that think it is correct and some that think it is not correct. Luckily we think it is not correct, so it is on a fix list.

Most likely this was done due to some "mistaken" optimization process, but anyhow...

The workaround is simple as the problem is that WHILE is not a relational command, and as it is NOT a relational command it does not trigger a recalculation of relational dependencies.

So to get it to work one need to take advantage of this "knowledge" and introduce a relational command in the equation.

We simply do that by creating a table called DUMMY with one row and one record.

In our sample the original DQL looks like this:

define "Retval" text .

define "howmany" number .

define "counter" number .

while Counter <3 do

counter := counter + 1 .

howmany := count of somedata with Key = counter .

list records

Counter ;

howmany .

end .

To make it simple we have 1 row with key 1, 2 rows with key 2 and 3 rows with key 3...

The result of the Normal While is like this:

Key: 1 HowMany? 1

Key: 2 HowMany? 1

Key: 3 HowMany? 1

Obviously wrong, as it only calculate the count of once (would be the same with any, sum of etc.)

So we change the DQL to look like this:

define "Retval" text .

define "howmany" number .

define "counter" number .

while Counter <3 do

counter := counter + 1 .

for Dummy ;

howmany := count of somedata with Key = counter .

end

list records

Counter ;

howmany .

end .

And then suddenly everything is Honkey Dorey...

Key: 1 HowMany? 1

Key: 2 HowMany? 2

Key: 3 HowMany? 3

Written by DataEase 16/10/15 at 12:07:02 Dataease [{8}]FIVE

Re:Re:count of not updated in a while loop

Thanks that works!

Written by George Washington 16/10/15 at 14:36:15 Dataease [{8}]FIVE