‎2008 Jan 23 12:28 PM
Hi All,
i have a problem in sorting an internal table.
i have used the statement
sort itab ascending.
here it should sort the able comparing all fields.
it works in some cases and insome case not. i am not able to understand why its not working in some cases.kindly let me know.
thanks in advance
sundeep
‎2008 Jan 23 12:31 PM
Hi
SORT statement works..
Let us know what cases it failed..
To get better results and with good performance, always use the fields by which u need to sort the table like:
SORT itab by FLD1 FLD2..
CHeers
Shakir
‎2008 Jan 23 12:33 PM
hi sundeep,
You can sort a standard or hashed table in a program. To sort a table by its key, use the statement
SORT <itab> [ASCENDING] [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.
The number of sort fields is restricted to 250.
The sorting process is not stable, i.e. if no sort is performed for a predefined sequence of fields, the sequence is not retained.
To delete all duplicate entries from a sorted internal table, you can specify DELETE ADJACENT DUPLICATES FROM itab after SORT .
The sort itself uses the Quicksort process where the key fields for all the data records are retrieved and placed in an area of main memory.
If there is not enough space in memory, the key fields are written to a temporary file and sorted by an external sort program. You can modify the directory which the SORT uses to store such auxiliary files by modifying the SAP profile parameter DIR_SORTTMP . Normally, auxiliary files are created in the SAP data directory (SAP profile parameter DIR_DATA ).
Hope this is helpful, Do reward.
Edited by: Runal Singh on Jan 23, 2008 6:04 PM
Edited by: Runal Singh on Jan 23, 2008 6:06 PM
‎2008 Jan 23 12:34 PM
Try to sort the tables by key fields or by giving keys.
like
sort i_ekko by ebeln.
reward points for helpful answer
kushagra
‎2008 Jan 23 12:35 PM
Hi sundeep,
If you do not specify any field in the SORT command, it considers the non-numeric fields from the left to right to sort the internal table. If you can specify the keys, it will be much better and it improves performance.
Reward points if useful,
Dru
‎2008 Jan 23 12:40 PM
Hi
i want to sort the table and delete adujuscent duplicates comparing all fields
‎2008 Jan 23 12:45 PM
SORT itab by FLD1 FLD2 FLD3.
DELETE ADJACENT DUPLICATES FROM itab comparing FLD1 FLD2 FLD3.
This will solve ur problem..
Cheers
Shakir
‎2008 Jan 23 12:38 PM
Have you defined keys in your table, SORT without explicitly declare the keys may use keys of the definition.
>The entries in the internal table are sorted in ascending order using the key from the table definition
Use AS TEXT addition if multi-lingual, unicode, etc.
> Text fields are sorted appropriate to the locale. This means that the relative order > of characters is defined according to the text environment being used.
Has the table more than 250 fields
> The number of sort fields is restricted to 250
Have some of the fields a conversion exit, sort will use internal value and not external value.
Regards
‎2008 Jan 25 11:45 AM
‎2008 Jan 25 11:45 AM