Sort on Enumvalues rather than data.
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
Hi,
You need a mapping between your codes and a sort order.
This can be achieved using a lookup, e.g. DICTIONARY.
Something like this:
Does this fit your needs?
Allan
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'}
,{'NVS','C','ABC'}
,{'A','X','BAC'}
,{'B','G','PQR'}
,{'A','B','AAC'}
,{'NVS','T','AAA'}],MyRec);
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);
Srtd_values_ds;
Does this fit your needs?
Allan
- Allan
- Posts: 444
- Joined: Sat Oct 01, 2011 7:26 pm
2 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest