Question
· Apr 23, 2021

Sort alphabetically a list of names

Hello everyone,

I don't want to believe that Intersystems didn't add a method/process/rule to sort alphabetically a list of names (in array, $ LB or whatever)

I haven't found any documentation about this. I've even tried comparing two strings but have not found a solution.

My cry for help is...

Does exists any command to compare two strings and check if one of them is lower or upper according to aphabet?

Please, give me a light in this dark

Best regards.
Kurro Lopez

Product version: HealthShare 2017.2
$ZV: Cache for Windows (x86-64) 2017.2.1 (Build 801_3U) Thu Apr 12 2018 10:02:23 EDT
Discussion (7)4
Log in or sign up to continue

Thanks mate for your answer.

My goal was create an string with all codes of activity from a list, and it should be in order alphabetical because the list could be in other order and this key should be the same

ClassMethod CreateKey(pList As %Collection.ListOfObj) As %String
{
        for i=1:1:pList.Count()
        {
            set code = pList.GetAt(i).Codigo
            set list(code)=""
        }
        
        set myKey = ""
        set key=$ORDER(list(""))
        while (key'="")
        {
            set myKey = myKey_key_"#"
            set key=$ORDER(lista(key))
        }

        return myKey 
}

Thanks for all your time and all explications about this.

Best regards,
Kurro

The reason that there is no sort "function", is that sorting is part of the basic storage structure that the whole system is built on. Arrays, both global and local, are automatically sorted as you set them up (effectively by an insertion sort). No need for a separate program or request. Just set up the data in an array as you go along and it will be sorted when you need it. This has always been a basic idea in the language, right from the original MUMPS, so the documentation may well skip over it a bit. However, when you get used to it, it works well.