Skip to content

ABAP Keyword Documentation →  ABAP - Quick Reference 

SORT itab - Quick reference

Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


SORT itab [STABLE] 
          { { [ASCENDING|DESCENDING]
              [AS TEXT]
              [BY {comp1 [ASCENDING|DESCENDING] [AS TEXT]}
                  {comp2 [ASCENDING|DESCENDING] [AS TEXT]}
                  ... ] }
          | { [BY (otab)] }
          | { [BY expr] } }.

Effect

Sorts an internal table itab by the primary table key or a specified sort key.

Additions

  • STABLE
    Ensures stable sorting by preserving the relative order of non-affected rows.
  • ASCENDING
    Sorts in ascending order.
  • DESCENDING
    Sorts in descending order.
  • AS TEXT
    Sorts text-like components in accordance with the locale of the current text environment.
  • BY comp1 ... comp2 ...
    Sorts by the specified components comp1, comp2, ... instead of by the primary table key.
  • BY (otab)
    Sorts by the order specified in the table otab of type ABAP_SORTORDER_TAB instead of by the primary table key.
  • BY expr
    Sorts by an internal table returned by an expression.