Mon May 17, 2021 9:39 pm
Login Register Lost Password? Contact Us

Sort on Enum Values

Comments and questions related to the Enterprise Control Language

Wed Apr 21, 2021 8:49 am Change Time Zone

Hi ALL ,
In case have to sort on enum values rather the column values as need is in specific order
and which has to be consistent and in control rather to be dependent on data.
Is there a way to sort

MyRec := {STRING3 Value1,STRING3 Category1, STRING3 Category2};
SomeFile := DATASET([{'NVS','T','ABC'},{'NVS','C','ABC'},{'A','X','BAC'},

srtvalues := enum(unsigned1,AAA, ABC, BAC,AAC,PQR);
//need to sort on values of 3rd field which is static but can add latter
Srtd_values_ds := sort(SomeFile,srtvalues.AAA);
Posts: 26
Joined: Fri Feb 23, 2018 8:30 am

Wed Apr 21, 2021 1:10 pm Change Time Zone

You could just PROJECT (or Vertical Slice TABLE) to add / replace the ENUM values with specific integers say, then, with output from this PROJECT sort on that integer?

Actually the ref manual says:
A comma-delimited list of expressions or key fields.
So 'expression' could be the return from a DICTIONARY lookup that converts ENUM to a required sort order?
Posts: 435
Joined: Sat Oct 01, 2011 7:26 pm

Wed Apr 21, 2021 2:40 pm Change Time Zone

Code: Select all
ds := DATASET([{'Payload1','ABA'}
              ],{STRING payload,STRING3 Itm});
Codes := DATASET([{'ABA' ,3 },
                   {'BBB' ,2 },
                   {'AAA' ,1 },
                   {'BBA' ,0 }], {STRING code,UNSIGNED1 sortPosition});

Lokup := DICTIONARY(Codes,{code => sortPosition});

Posts: 435
Joined: Sat Oct 01, 2011 7:26 pm

Return to ECL

Who is online

Users browsing this forum: No registered users and 1 guest