Sat Sep 18, 2021 9:41 am
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'},
{'B','G','PQR'},{'A','B','AAC'},{'NVS','T','AAA'}],MyRec);

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);
harshdesai
 
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?
Yours
Allan

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?
Allan
 
Posts: 439
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'}
              ,{'Payload2','BBB'}
              ,{'Payload3','AAA'}
              ,{'Payload4','BBA'}
              ],{STRING payload,STRING3 Itm});
               
Codes := DATASET([{'ABA' ,3 },
                   {'BBB' ,2 },
                   {'AAA' ,1 },
                   {'BBA' ,0 }], {STRING code,UNSIGNED1 sortPosition});

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

SORT(ds,Lokup[Itm].sortPosition);
Allan
 
Posts: 439
Joined: Sat Oct 01, 2011 7:26 pm


Return to ECL

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron