ABAP SORT statement with Internal tables

In ABAP programming SORT is the keywords for sorting the internal table field data in an order. See the Syntax. We can specify the order like Ascending or Descending with the statement. When the SORT statement execute, data from internal table will be stored in memory and sorting process occurs using the quick-sort ( its a special type of sorting algorithm ) method. There is one issue that, if any failure occurred, all the data in internal table will loose.

Its syntax is
SORT itab. ( Sorting data from Internal table)
Additions used with this syntax

  • DESCENDING
  • ASCENDING
  • BY fieldname1 fieldname2 ..

SORT. ( Sorting the data from EXTRACT)
Additions used with this syntax

  • DESCENDING
  • ASCENDING
  • BY fieldname1 fieldname2 ..
  • BY field_group ( sorting the fields contained in specified field group header )

“AS text” addition is dealing with sorting in alphabetical order, it can be used for sorting strings in the table ( Sorting in name wise etc )

Main run-time errors with this Statement execution

  • SORT_EXTRACT_TOO_MANY_FIELDS
  • SORT_FIELD_NOT_IN_HEADER
  • SORT_NO_HEADER
  • SORT_WITHIN_LOOP

Here is a sample program with SORT statement with ABAP internal table

ABAP SORT STATEMENT _ INTERNAL TABLES