1. Alexander Busch
  2. PowerBuilder
  3. Thursday, 14 March 2024 08:21 AM UTC

Hello Appeon, 

Our PowerBuilder Version is: 22.1.0.2828


Numbers are sorted based on an alphabetical value, instead of numerical value, like one would expect from a natural sort, where multiple digits are treated as one character. 

I.e.: 
Natural sort 
1, 2, 10, 20

 

Instead of: 1, 10, 2, 20

Is there a built-in way to remedy this? 

Greetings, 
Alexander

 

Jeff Wayt Accepted Answer Pending Moderation
  1. Wednesday, 20 March 2024 15:42 PM UTC
  2. PowerBuilder
  3. # 1

I have a line number column the users can edit and add letters. Line numbers are generated, incremented with each new line. They can do what they please.

I do two things. I increment by tens. I zero-fill, right justify to 3 digits: 010, 020, 030, etc. If the user wants to renumber, there is an easy gap.

Another trick is to make my own column to retain the sequence they added detail, so what ever they do retains that order. It is helpful to add drag and drop so they can drag rows in what ever order, then I resequence on my own column.

Comment
There are no comments made yet.
Felix Kock Accepted Answer Pending Moderation
  1. Tuesday, 19 March 2024 08:06 AM UTC
  2. PowerBuilder
  3. # 2

The column type is string.

Converting to integer and then sorting is not an option for us, as we have to expect numbers in the middle of the string (i.e.: "AAA-10-BB" ).

Could you give an example for the format?

In general we were hoping for a native solution within Powerbuilder, as tinkering with the sort function would probably wreck our performance, since it needs to be used across almost all application parts

Thanks anyway

Comment
  1. Felix Kock
  2. Tuesday, 19 March 2024 10:30 AM UTC
There can be multiple numbers in a string and they are completely arbitrary



Example Data

"A", "a", "B", "b", "1", "2", "10", "20", "A1", "A2", "A10", "b1", "b2", "b10", "2b10a", "2b2a"



Sorted as (ascending):

1

2

2b2a

2b10a

10

20

A

a

A1

A2

A10

B

b

b1

b2

b10
  1. Helpful
  1. René Ullrich
  2. Tuesday, 19 March 2024 10:42 AM UTC
I don't know a way to sort this using PB. If you have only values with numbers and other values only with characters you could probably solve it using more complex sort criteria. But with combinations of numbers and characters in strings it would be not possible, I think.
  1. Helpful
  1. Arnd Schmidt
  2. Tuesday, 19 March 2024 13:43 PM UTC
You can write a global function and use "f_to_natural (my_horror_field)" as Sort Expression.

  1. Helpful
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Thursday, 14 March 2024 09:48 AM UTC
  2. PowerBuilder
  3. # 3

Is column type a numerical or a string type?

Comment
  1. Sivaprakash BKR
  2. Thursday, 14 March 2024 10:15 AM UTC
Yes, if the column's data type is string then the result will be the same as you get (1, 10, 2, 20 ...).

One way is to sort after converting the values to integer.
  1. Helpful
  1. Miguel Leeuwe
  2. Thursday, 14 March 2024 10:52 AM UTC
Or determine your highest number and then do a left fill with 0's of the string values.
  1. Helpful 2
  1. René Ullrich
  2. Thursday, 14 March 2024 10:56 AM UTC
or use a format for number with fixed numbers of 0's and sort by lookupvalue
  1. Helpful 3
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.