Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

With which algorithm works the SORT statement?

0 Kudos

Hello everybody,

can somebody tell me how the SORT statement is working? Or show me a chapter in the documentation where its described.

And what is different to SORT stable.

Best regards,

Christian

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi

good

You can sort a standard or hashed table in a program. To sort a table by its key, use the statement

SORT <itab> [ASCENDING|DESCENDING] [AS TEXT] [STABLE].

The statement sorts the internal table <itab> in ascending order by its key. The statement always applies to the table itself, not to the header line. The sort order depends on the sequence of the standard key fields in the internal table. The default key is made up of the non-numeric fields of the table line in the order in which they occur.

You can specify the direction of the sort using the additions ASCENDING and DESCENDING. The default is ascending.

The larger the sort key, the more time the system needs to sort the table. If the sort key contains an internal table, the sorting process may be slowed down considerably.

You cannot sort a sorted table using the SORT statement. The system always maintains these tables automatically by their sort order. If an internal table is statically recognizable as a sorted table, the SORT statement causes a syntax error. If the table is a generic sorted table, the SORT statement causes a runtime error if the sort key is not the same as an extract of the beginning of the table key, you sort in descending order, or use the AS TEXT addition. In other words, the SORT statement is only allowed for generic internal tables, if it does not violate the internal sort order.

<b><REMOVED BY MODERATOR></b>

thanks

mrutyun^

Message was edited by:

Alvaro Tejada Galindo

5 REPLIES 5

Former Member
0 Kudos

Well, if you do not specify STABLE, then when you sort by a particular field, the other fields that you are not sorting by may be in a different order than they were before the sort statement.

Rob

Former Member
0 Kudos

..

Message was edited by:

Perez C

Former Member
0 Kudos

hi

good

You can sort a standard or hashed table in a program. To sort a table by its key, use the statement

SORT <itab> [ASCENDING|DESCENDING] [AS TEXT] [STABLE].

The statement sorts the internal table <itab> in ascending order by its key. The statement always applies to the table itself, not to the header line. The sort order depends on the sequence of the standard key fields in the internal table. The default key is made up of the non-numeric fields of the table line in the order in which they occur.

You can specify the direction of the sort using the additions ASCENDING and DESCENDING. The default is ascending.

The larger the sort key, the more time the system needs to sort the table. If the sort key contains an internal table, the sorting process may be slowed down considerably.

You cannot sort a sorted table using the SORT statement. The system always maintains these tables automatically by their sort order. If an internal table is statically recognizable as a sorted table, the SORT statement causes a syntax error. If the table is a generic sorted table, the SORT statement causes a runtime error if the sort key is not the same as an extract of the beginning of the table key, you sort in descending order, or use the AS TEXT addition. In other words, the SORT statement is only allowed for generic internal tables, if it does not violate the internal sort order.

<b><REMOVED BY MODERATOR></b>

thanks

mrutyun^

Message was edited by:

Alvaro Tejada Galindo

0 Kudos

Hi all,

thanks for your reply. One Question is left. What algorithm is used e.g. Bubble Sort or Quick Sort or whatever! Or is that one of walldorf secrets!?

Best regards,

Christian

0 Kudos

Don't know if it's a secret or not, but if you search for notes related to bubble sort or quicksort, you'll find some information.

Rob