‎2006 Nov 28 11:48 AM
Can you tell how to write Sort statement in ABAP 4.6 Version
‎2006 Nov 28 11:50 AM
‎2006 Nov 28 11:50 AM
‎2006 Nov 28 11:50 AM
‎2006 Nov 28 11:50 AM
‎2006 Nov 28 11:50 AM
Here we have some more details:
SORT itab ASCENDING
Extras:
1. ... ASCENDING|DESCENDING
2. ... AS TEXT
3. ... STABLE
Effect
This statement sorts an internal table itab. As standard, numeric and byte-type components are sorted according to their value and character-type by their binary representation (code page). For text-based sorting of character-type components, you can use the addition AS TEXT.
For itab, a standard table or hashed table is expected. Sorted tables cannot be sorted using SORT. If no explicit sort key sort_key is specified, the internal table itab is sorted by the table key, whereby the table key can contain a maximum of 250 components. The priority of sorting is determined by the order in which the key fields are specified in the table definition. For the standard key, the priority of the sort depends on the order of the key fields in the line type of the table.
It is syntactically forbidden to use the SORT statement on sorted tables. If it is not determined until runtime that a sorted table is to be sorted, this leads to an untreatable exception if the sort could change the existing sorted order. This happens in the following cases:
If the sort key specified in sort_key is different to the initial part of the table key
If the addition DESCENDING is used
If the addition AS TEXT is used
If an attribute of an object is specified as a component in sort_key.
Otherwise the SORT statement is ignored for sorted tables.
Addition 1
... ASCENDING|DESCENDING
Effect
You can use the additions ASCENDING or DESCENDING to explicitly define whether the table is sorted in ascending or descending order. If neither addition is specified, the data is sorted in ascending order by default. This sort order can be overwritten for individual components in the explicit sort key sort_key.
Addition 2
... AS TEXT
Effect
The addition AS TEXT specifies that text-type components are sorted according to the locale of the current text environment. If AS TEXT is not specified, text-type components are sorted according to the coding in the code page of the current text environment. This specification can be overwritten for individual text-type components in the explicit sort key sort_key. The text environment is set when an internal session is opened, or using the statement SET LOCALE.
Notes
Sorting without the AS TEXT addition is considerably faster than sorting using the addition. If text-type components only contain characters of the ASCII character set, both sort options result in the same sort order and the addition AS TEXT is not necessary.
The result of lexicographic sorting depends on the operating system of the application server. While the sequence of the individual letters that belong to the activated language is the same for all operating systems, there are differences in the characters that do not belong to the alphabet of the activated language. When sorting whole words, there are also slight differences even if only using letters from the alphabet of the activated language. The order of upper and lower case letters also depends on the operating system.
For the AS TEXT addition to function correctly, the profile parameter install/collate/active must not have the value 0.
The use of the AS TEXT addition normally renders the statement CONVERT TEXT superfluous.
Addition 3
...STABLE
Effect
You can use STABLE to ensure a stable sort order. This means that the order of lines, which is the same in the sort key, remains unchanged after sorting. Without the STABLE addition, the order is not preserved and repeated sorting of a table by the same sort key changes the order each time the table is sorted.
Example
Sorting a hashed table text_tab by the order in the code page and according to the locale of the current text environment. If a Western European text environment is set, sorting results in the orders Miller, Moller, Muller, Möller, or Miller, Moller, Möller, Muller (also see the example for SET LOCALE).
DATA text_tab TYPE HASHED TABLE OF string
WITH UNIQUE KEY table_line.
INSERT: `Muller` INTO TABLE text_tab,
`Möller` INTO TABLE text_tab,
`Moller` INTO TABLE text_tab,
`Miller` INTO TABLE text_tab.
SORT text_tab.
PERFORM write_text_tab.
SORT text_tab AS TEXT.
PERFORM write_text_tab.
FORM write_text_tab.
FIELD-SYMBOLS TYPE string.
LOOP AT text_tab ASSIGNING .
WRITE / .
ENDLOOP.
SKIP.
ENDFORM.
‎2006 Nov 28 11:51 AM
Hi,
1.Sory itab BY f1 f2 ... fn
2. ... ASCENDING
3. ... DESCENDING
4. ... AS TEXT
5. ... STABLE
regards,
Kumar
‎2006 Nov 28 11:51 AM
now u have internal table with fields matnr, maktx, werks etc....
say Matnr is primary key along with werks...So, need to sort on these fields for further processing.
sort <internaltable> by matnr werks,
‎2006 Nov 28 11:52 AM
SORT table name BY fields(in that table).
ex: sort it_vbak by vbeln.
‎2006 Nov 28 11:52 AM
Hi Rajasekhar,
welcome to SDN.
basic systax of sort is
SORT itab.
with following addition
1. ... BY f1 f2 ... fn (field names)
2. ... ASCENDING
3. ... DESCENDING
4. ... AS TEXT
5. ... STABLE
hope this helps .
award forum points to helpful answers
‎2006 Nov 28 11:53 AM
‎2006 Nov 28 11:53 AM