Sort on Enum Values
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);
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: 29
- Joined: Fri Feb 23, 2018 8:30 am
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?
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: 444
- Joined: Sat Oct 01, 2011 7:26 pm
- 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: 444
- Joined: Sat Oct 01, 2011 7:26 pm
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest