# Maximum value of a field in a queue

**URL:** <https://clarionhub.com/t/maximum-value-of-a-field-in-a-queue/6644>\
**Category:** questions\
**Tags:** queue, c11\
**Created:** [October 3, 2023, 6:31pm UTC](https://clarionhub.com/t/maximum-value-of-a-field-in-a-queue/6644 "2023-10-03T18:31:47Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![DonnEdwards](https://clarionhub.com/user_avatar/clarionhub.com/donnedwards/32/1047_2.png) [@DonnEdwards](https://clarionhub.com/u/DonnEdwards)\
**Post date:** [October 3, 2023, 6:31pm UTC](https://clarionhub.com/t/maximum-value-of-a-field-in-a-queue/6644/1 "2023-10-03T18:31:47Z")

</div>

I have a series of records that I have loaded into a queue. The primary key field is StepId and I want to find the largest value of StepId in the queue. I could inspect each record as I load it into the queue, but I’m wondering if there is a quicker way. Also, if the queue is in a browse form, the data has already been loaded. I don’t want to have to rummage through several thousand records to find it.

In _Visual Basic_ there is a function **DMAX** (“field”,“domain”,“where clause”) which returns the maximum value of a field in the domain (usually a table or query) that corresponds to the optional where clause. Similarly, _Visual Basic_ has a **DMIN** function for the minimum value.

Is there a Clarion equivalent or a preferred method? I appreciate any thoughts or suggestions.  
Donn

---

<div class="post-metadata">

**Author:** ![jslarve](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@jslarve](https://clarionhub.com/u/jslarve)\
**Post date:** [October 3, 2023, 6:37pm UTC](https://clarionhub.com/t/maximum-value-of-a-field-in-a-queue/6644/2 "2023-10-03T18:37:30Z")

</div>

Unless you can SORT by that field, I think you’ll just be looping through the queue.

---

<div class="post-metadata">

**Author:** ![DonnEdwards](https://clarionhub.com/user_avatar/clarionhub.com/donnedwards/32/1047_2.png) [@DonnEdwards](https://clarionhub.com/u/DonnEdwards)\
**Post date:** [October 3, 2023, 6:44pm UTC](https://clarionhub.com/t/maximum-value-of-a-field-in-a-queue/6644/3 "2023-10-03T18:44:53Z")

</div>

Do you mean doing a sort and then going to the last record, which I would find by using the RECORDS(QueName) command? Didn’t think of that.

---

<div class="post-metadata">

**Author:** ![jslarve](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@jslarve](https://clarionhub.com/u/jslarve)\
**Post date:** [October 3, 2023, 6:48pm UTC](https://clarionhub.com/t/maximum-value-of-a-field-in-a-queue/6644/4 "2023-10-03T18:48:02Z")

</div>

Yes, but maybe a frequent sort would not be great for your purpose. Just depends on what you’re doing with the queue.

---

<div class="post-metadata">

**Author:** ![anon77170705](https://clarionhub.com/letter_avatar_proxy/v4/letter/a/ecccb3/32.png) [@anon77170705](https://clarionhub.com/u/anon77170705)\
**Post date:** [October 3, 2023, 11:23pm UTC](https://clarionhub.com/t/maximum-value-of-a-field-in-a-queue/6644/5 "2023-10-03T23:23:28Z")

</div>

> [@jslarve](#):
>
> Unless you can SORT by that field

QUEUEs since C5 can handle multiple sort orders. It’s enough to use any queue function with required sort parameters, for example, GET(queue,-queue.field)

---

<div class="post-metadata">

**Author:** ![jslarve](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@jslarve](https://clarionhub.com/u/jslarve)\
**Post date:** [October 3, 2023, 11:42pm UTC](https://clarionhub.com/t/maximum-value-of-a-field-in-a-queue/6644/6 "2023-10-03T23:42:06Z")

</div>

If you have a queue as a FROM() in a listbox, can you sort that queue in such a way to get the largest value of a field and not disturb the listbox’s sort order? If not, I am not sure how to take advantage of the multiple sort orders.  
In addition, would a SORT() change the value of CHANGES()?

Thank you.

---

<div class="post-metadata">

**Author:** ![anon77170705](https://clarionhub.com/letter_avatar_proxy/v4/letter/a/ecccb3/32.png) [@anon77170705](https://clarionhub.com/u/anon77170705)\
**Post date:** [October 4, 2023, 12:24am UTC](https://clarionhub.com/t/maximum-value-of-a-field-in-a-queue/6644/7 "2023-10-04T00:24:52Z")

</div>

> [@jslarve](#):
>
> If you have a queue as a FROM() in a listbox, can you sort that queue in such a way to get the largest value of a field and not disturb the listbox’s sort order?

LIST controls with a queue as a parameter of FROM uses the **current** sort order. Current sort order is the order set by the last SORT statement, or, if none explicit SORT has been executed, it’s the order set by the ADD statement inserted a first record to the empty queue. For example,

```auto
  FREE (que)
  ...set fields of the que...
  ADD (que)

```

sets current sort order to unsorted.

> [@jslarve](#):
>
> If not, I am not sure how to take advantage of the multiple sort orders.

Usage of queues is no limited to LISTs’ FROM attributes.

> [@jslarve](#):
>
> In addition, would a SORT() change the value of CHANGES()?

No.

---

<div class="post-metadata">

**Author:** ![Julian](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@Julian](https://clarionhub.com/u/Julian)\
**Post date:** [October 4, 2023, 8:13am UTC](https://clarionhub.com/t/maximum-value-of-a-field-in-a-queue/6644/8 "2023-10-04T08:13:15Z")

</div>

When I do something similar I add to the queue like this .. ADD(Q,StepID)

After building, the last record in the queue has the highest value so I simply read it back thus .. GET(Q,RECORDS(Q))

---

<div class="post-metadata">

**Author:** ![DonnEdwards](https://clarionhub.com/user_avatar/clarionhub.com/donnedwards/32/1047_2.png) [@DonnEdwards](https://clarionhub.com/u/DonnEdwards)\
**Post date:** [October 7, 2023, 4:59pm UTC](https://clarionhub.com/t/maximum-value-of-a-field-in-a-queue/6644/9 "2023-10-07T16:59:03Z")

</div>

In this case, that approach will not work because the lowest value is 100 and the highest value is 300 and there are plenty of gaps in between. I suspect RECORDS(Q) will return 21.

 ![clFixerActions](https://clarionhub-uploads.s3.eu-north-1.amazonaws.com/original/2X/f/fa7efe358410643fe5c1edd8800be9ec9c9ebbb7.png)

Still, I thank everyone who contributed, and made me think outside the box too 😀

---

<div class="post-metadata">

**Author:** ![Jane](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/ecb155/32.png) [@Jane](https://clarionhub.com/u/Jane)\
**Post date:** [October 7, 2023, 5:22pm UTC](https://clarionhub.com/t/maximum-value-of-a-field-in-a-queue/6644/10 "2023-10-07T17:22:05Z")

</div>

> [@DonnEdwards](#):
>
> I suspect RECORDS(Q) will return 21.

In which case, GET(Q,21) will return the 21st record in the queue in its current sort order.

---

<div class="post-metadata">

**Author:** ![jslarve](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@jslarve](https://clarionhub.com/u/jslarve)\
**Post date:** [October 7, 2023, 5:45pm UTC](https://clarionhub.com/t/maximum-value-of-a-field-in-a-queue/6644/11 "2023-10-07T17:45:08Z")

</div>

I believe they intended for you to use that result to GET() the queue when sorted by the value in question.

---

<div class="post-metadata">

**Author:** ![Julian](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@Julian](https://clarionhub.com/u/Julian)\
**Post date:** [October 7, 2023, 6:28pm UTC](https://clarionhub.com/t/maximum-value-of-a-field-in-a-queue/6644/12 "2023-10-07T18:28:36Z")

</div>

> [@DonnEdwards](#):
>
> In this case, that approach will not work because the lowest value is 100 and the highest value is 300 and there are plenty of gaps in between. I suspect RECORDS(Q) will return 21.

I do not understand what you mean by this comment.  
Assuming you are referring to my suggestion .. the number of records in the queue is not relevant, neither are any gaps in the sequence, ADDing to the queue using the ADD(Q,Q.StepiD) method will always ensure that the very last record always has the highest value of StepID and GET(Q,RECORDS(Q)) will allow you to examine Q.StepD value.

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [October 8, 2023, 12:44am UTC](https://clarionhub.com/t/maximum-value-of-a-field-in-a-queue/6644/13 "2023-10-08T00:44:28Z")

</div>

> [@anon77170705](#):
>
> > [@jslarve](#):
> >
> > In addition, would a SORT() change the value of CHANGES()?
> 
> No.

The Help says SORT increments CHANGES() ID and it makes sense to me that it does because the is QUEUE changed by SORT.

> If any of these five statements act on the QUEUE the Change ID is incremented: FREE() ADD() PUT() DELETE() SORT()… If a SORT does not change the order the Change ID is still incremented. The Change ID is simply a count of likely changes.

Ahhh… I may have written that because I know the original Help discussing a Hash Value was wrong. I’m sure I tested it. IIRC DAB discussed CHANGES() needing to be a simple thing that indicated a “likely change”, it was not worth the effort to precisely determine changes. I use CHANGES() to decide if a LIST needs refreshing, e.g. with a VLB asking for Row -3

[http://clarion.help/doku.php?id=changes\_return\_changed\_queue\_.htm](http://clarion.help/doku.php?id=changes_return_changed_queue_.htm)

* * *

> [@DonnEdwards](#):
>
> I could inspect each record as I load it into the queue, but I’m wondering if there is a quicker way.

I think the best way would be to “inspect each record as I load it”

Other ways mean SORT the entire Queue, or scanning it all with a LOOP and GET. That’s more processing, especially as there are more records.

---

<div class="post-metadata">

**Author:** ![DonnEdwards](https://clarionhub.com/user_avatar/clarionhub.com/donnedwards/32/1047_2.png) [@DonnEdwards](https://clarionhub.com/u/DonnEdwards)\
**Post date:** [October 8, 2023, 8:43am UTC](https://clarionhub.com/t/maximum-value-of-a-field-in-a-queue/6644/14 "2023-10-08T08:43:58Z")

</div>

> [@Julian](#):
>
> I do not understand what you mean by this comment.

I misread and therefore misunderstood your code. Sorry!

---

<div class="post-metadata">

**Author:** ![anon77170705](https://clarionhub.com/letter_avatar_proxy/v4/letter/a/ecccb3/32.png) [@anon77170705](https://clarionhub.com/u/anon77170705)\
**Post date:** [October 8, 2023, 12:16pm UTC](https://clarionhub.com/t/maximum-value-of-a-field-in-a-queue/6644/15 "2023-10-08T12:16:58Z")

</div>

> [@CarlBarnes](#):
>
> The Help says SORT increments CHANGES() ID and it makes sense to me that it does because the is QUEUE changed by SORT.

You’re correct. I missed some code when looked where the changes counter is incrementing.
