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: 

sorting internal table

Former Member
0 Kudos

Hi all,

I have a scenario wherein i have to sort the internal table without using the sort function( i.e sort syntax).Is there any logic.

Can nebody pls help me out.

Regards

Jak

9 REPLIES 9

matt
Active Contributor
0 Kudos

What's so strange about the scenario that you can't use the standard SORT command?

You could implement a sort algorithm yourself, but most times, even if the sort order is a bit odd, you can still use the SORT command, if you arrange the data correctly.

What's the scenario?

matt

Former Member
0 Kudos

U can code as normal buble sort machanism (like in c or c++)

Reward if useful

0 Kudos

Hi narendra

Thankx for ur reply. Can u pls code me the buble sort logic.

regards

jak

0 Kudos

Hai,

To understand bubble sort, think of an air bubble rising in water

To sort N items, N passes are made through the data.

The result of the first pass is that the smallest item is in the last location of the array.

The result of the second pass is that the second smallest item is in the second last location of the array.

etc.

After N passes, the entire array is sorted.

The operation in each pass is as follows:

First, the values in the first two locations are compared. If necessary the values are exchanged, so that the smaller one is last.

Then, the values in the second and third locations are compared. If necessary the values are exchanged, so that again the smaller one is last.

This process repeats to the end of the array.

In effect, the smaller item bubbles its way towards the top. It keeps on going until either it reaches the top (and the pass ends), or it strikes a smaller item. In that case it stops itself, and gives that smaller item a nudge to start it on its way.

If a complete pass is made without any exchanges being made, the data must already be sorted. This is easily checked. Thus it might be possible to halt the algorithm without going through all N passes.

Azeemquadri
Contributor
0 Kudos

try sort stable.

Former Member
0 Kudos

Declare the internal table as sorted.

Refer to the below link for syntax:

http://help.sap.com/erp2005_ehp_03/helpdata/EN/fc/eb35de358411d1829f0000e829fbfe/frameset.htm

Former Member
0 Kudos

i cant think of any scenarion in which you can NOT use the SORT statement.

but well you can program e.G. a bubblesort algorithm yourself. Just be aware that a bubblesort is quite slow.

Former Member
0 Kudos

Hi,

SORT for Internal Tables

Sorts internal tables.

Syntax

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

... BY <fi> [ASCENDING|DESCENDING] [AS TEXT]...

Sorts the internal table <itab>. If you omit the BY addition, the table is sorted by its key. You can define a different sort key by using the BY addition. The other additions specify whether you want to sort in ascending or descending order, and whether strings should be sorted alphabetically.

Regards,

Priya.

vinod_vemuru2
Active Contributor
0 Kudos

Hi,

I will sugest 2 solutions for u.

1. Use ORDER BY clause (Obsolete) in ur select.

2. Declare the internal table as TYPE SORTED TABLE OF.

Thanks,

Vinod.