11

Why does my ABAP program short dump when I append a line to a sorted table?

ST22 Shows ITAB_ILLEGAL_SORT_ORDER

data: sorted_tab type sorted table of ty_tab with non-unique key key,
      line       type ty_tab.

line-key = 1. 
append line to sorted_tab.  "works fine" 

line-key = 2. 
append line to sorted_tab.  "works fine" 

line-key = 1. 
append line to sorted_tab.  "<==== Short dump here" 
Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
Esti
  • 3,677
  • 8
  • 35
  • 57
  • 1
    This seems like a stupid question - but I've just wasted enough time to find the answer to save the next person some grief. (Google was helpful, SAP help was not) – Esti Oct 05 '09 at 06:09
  • 2
    please include the declaration of your sorted table! – Thorsten Oct 05 '09 at 10:20
  • good point - as if your table was declared with a unique key you would get yet another short dump – Esti Oct 05 '09 at 22:33

1 Answers1

20

The program short dumps when appending a sorted table in the wrong sort order

data: sorted_tab type sorted table of ty_tab with non-unique key key,
      line       type ty_tab.

line-key = 1.
append line to sorted_tab.  "works fine"

line-key = 2.
append line to sorted_tab.  "works fine"

line-key = 1.
append line to sorted_tab.  "<==== Short dump here"

Use INSERT in stead:

data: sorted_tab type sorted table of ty_tab with non-unique key key,
      line       type ty_tab.

line-key = 1.
insert line into table sorted_tab.  "works fine"

line-key = 2.
insert line into table sorted_tab.  "works fine"    

line-key = 1.
insert line into table sorted_tab.  "works fine"

Note If you had a UNIQUE key you would still get a short dump because you're using the same key twice

Esti
  • 3,677
  • 8
  • 35
  • 57