Queue Sort (Alphanumeric) - Sort Field or Queue Sort Function

Hello -

I have done this in past but can’t recall how this was done or find any example in help file:

I have a Queue, example:

NameQue QUEUE
Code STRING(10)
Name STRING(20)
END

Code can contain numeric and alpha values and when Sorted by Code, it sorts like:
1
10
100
101
2
3

How can I customize the sort to sort as:

1
2
3
10
100
101

NameQue.Code - needs to be STRING(10) as it can contain alphanumeric values, eg. ‘A100’

Thanks,
-Rex

If you change the data type to an integer, such as LONG, it will sort numerically.

: - Code column can contain alpha values too - A100, A101, etc.

You could either maintain a dummy column that contained a string formatted how you want it to sort, or you could use a sort function.

I thought there was an example of queue function sorting somewhere. You write a function that receives 2 *GROUPS, where you put the logic for which group is sorted first. But personally, I’d probably go with option 1 :slight_smile:

a) format the strings so they are numbers of fixed length - eg 001 not 1

b) use a “sort” column in the queue, usually invisible, and populate this with formatted strings (as per a above ) and sort on this.

c) create a custom Q sort function. If you have Stringtheory, look in Stringtheory.clw for an example of doing this - there are 3 functions (not methods) in there called SortCaseSensitive, SortCaseInsensitive and SortLength. For example;

!-----------------------------------------------------------------------------------
SortCaseInsensitive        Procedure(*LinesGroupType p1,*LinesGroupType p2)
  code
  if Upper(p1.line) = Upper(p2.line) then return 0.
  if Upper(p1.line) > Upper(p2.line) then return 1.
  return -1

called as;
sort(self.lines,SortCaseInsensitive)

Thanks for your suggestions. Since this is very limited use case, I will go with secondary field (invisible) for sorting.

Custom Q sort function was what I was trying to recall, I have used that in some old project and couldn’t find the example.

The hidden Sort field is the easiest. You can have the column visible while developing to debug. This code would not work to put 100A after 100, but will work with your example of A100.

IF Numeric(Q:Code) THEN 
  Q:SortCode=FORMAT(0+Q:Code,@n_10)
ELSE
  Q:SortCode=UPPER(Q:Code)
END 

For the best examples of Queue sorting search Clarion Live for Simon Kemp and you’ll find:

#348 Simon Kemp On Queue Functional Sorting

FEB 19,2016 Simon Kemp
This week, it’s Functional Queue Sorting with Simon Kemp! What is Functional Queue Sorting? I have no idea! But I’m looking forward to finding out!!!

#350 Simon Kemp On Queue Functional Sorting Part2

MAR 04,2016 Simon Kemp
Get the code here → (not specified) This week, it’s Functional Queue Sorting Part 2 with Simon Kemp! Two weeks ago, Simon started showing us about Functional Queue Sorting, but he had so much to show he couldn’t fit it into one webinar! Join him for Part 2 and learn even more amazing things about queue sorting!

Simon’s website changed from SdkSoftwaresolutions.com to http://sdksoftware.uk/ and has the download SdkLCS.zip used in the webinar. I had it and attached it here. Its very very useful, probably showing every possible Queue Sort function.

ClarionLive348_sdklcs_CLiveQueueSorting.zip (108.6 KB)

3 Likes

Very kind of you Carl, I tried hard on that ClarionLive stuff. And (if I’m honest) can’t recall the last time I found a use case. Pretty obscure stuff.
My domain changed to sdksoftware.uk a while ago…

Good to see you here, Simon.

I concur with Jeff, nice to hear from you Simon.

From the Webinar I easily recalled your initials were S.D.K. (as in “Software Dev Kit”) but searches for “SDK Software Simon Kemp” did not find it. Maybe you need to add some that SEO search word stuff.

The 2 Webinars completely cover Q sorting very well, and your example APP is great for having working code to use.

Having been christened Simon Dallas Kemp, seems fated I’d spend much of my life pretending to be a coder…

Any GUIs, CPUs, RAMs (or indeed TLAs) reading this have my sympathy.

:wine_glass:

Back in the day, I was the only JS.