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"
With a sorted table, it is not possible to use statement APPEND to add line in a table. APPEND will resquest to add the line at the end, which will perturbate the sort of table. Use statement INSERT, which will automatically manage in which index will be inserted the line.
APPEND will adds the line to the internal table one after the other, if the sort sequence is not kept the program will dump, on sorted table should use INSERT instead of APPEND.
To add several lines to an internal table, use the statement: INSERT LINES OF itab1 [FROM n1] [TO n2] INTO TABLE itab2. itab1 and itab2 are tables with a compatible line type. The system inserts the lines of table itab1 one by one into table itab2 using the same rules as for single lines.
Only the statement APPEND with the addition SORTED BY can be used to fill the internal table.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With