Wed Jun 23, 2021 2:31 pm
Login Register Lost Password? Contact Us

Sort on Enumvalues rather than data.

Questions around writing code and queries

Wed Apr 21, 2021 9:01 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

Mon Jun 21, 2021 9:29 am Change Time Zone

You need a mapping between your codes and a sort order.
This can be achieved using a lookup, e.g. DICTIONARY.
Something like this:
Code: Select all
MyRec := {STRING3 Value1,STRING3 Category1, STRING3 Category2};
SomeFile := DATASET([{'NVS','T','ABC'}

SortOrder := DATASET([{'AAA',1},{'ABC',2},{'BAC',3},{'AAC',4},{'PQR',5}],{STRING Code,UNSIGNED1 SortOrder});

Dict      := DICTIONARY(SortOrder,{Code => SortOrder});

Srtd_values_ds := sort(SomeFile,Dict[Category2].SortOrder);

Does this fit your needs?
Posts: 436
Joined: Sat Oct 01, 2011 7:26 pm

Return to Programming

Who is online

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