12-17-2008 6:08 PM
Hi there,
how can I use the APPEND LINES statment with sorted tables? Is this possible???
Kind regards
Max
12-17-2008 6:15 PM
Below is F1 help Of Append Lines:
"Appending square numbers to a "sorted table" with elementary row type.
DATA: int TYPE i,
itab LIKE SORTED TABLE OF int
WITH UNIQUE KEY table_line.
DO 10 TIMES.
int = sy-index ** 2.
APPEND int TO itab.
ENDDO.
12-17-2008 6:13 PM
12-17-2008 6:15 PM
Below is F1 help Of Append Lines:
"Appending square numbers to a "sorted table" with elementary row type.
DATA: int TYPE i,
itab LIKE SORTED TABLE OF int
WITH UNIQUE KEY table_line.
DO 10 TIMES.
int = sy-index ** 2.
APPEND int TO itab.
ENDDO.
12-17-2008 8:35 PM
Amit: the above example from you works, but the only reason for that is that the rows are appended according to the sort sequence (APPEND adds the line to the internal table one after the other). Once the sort sequence is not kept, the program will dump. An example to understand better:
Here the dump is acc. to the sort sequence, so it works:
APPEND 1.
APPEND 2.
APPEND 3.
Here the sort sequence is not kept:
APPEND 1.
APPEND 3.
APPEND 2. "this will dump at this line
As Jerry suggested already INSERT has to be used in case of SORTED (and HASHED) tables.
12-17-2008 9:06 PM
Hi Eric,
Agreed.
But If this is the Case you would get Dump With Insert Also.
APPEND 1.
APPEND 3.
APPEND 2. "Dump ITAB_ILLEGAL_SORT_ORDER
12-17-2008 9:15 PM
It works ok for me.
REPORT zztemp.
TYPES: BEGIN OF intline,
int TYPE i.
TYPES: END OF intline.
DATA: intline TYPE intline,
itab LIKE SORTED TABLE OF intline WITH UNIQUE KEY int.
intline-int = 3.
INSERT intline INTO TABLE itab.
intline-int = 5.
INSERT intline INTO TABLE itab.
intline-int = 1.
INSERT intline INTO TABLE itab.
intline-int = 2.
INSERT intline INTO TABLE itab.
LOOP AT itab INTO intline.
WRITE:/ intline-int.
ENDLOOP.
12-17-2008 9:36 PM
>
> But If this is the Case you would get Dump With Insert Also.
>
APPEND 1. > APPEND 3. > APPEND 2. "Dump ITAB_ILLEGAL_SORT_ORDER
with simply INSERT ... INTO yes, but the correct syntax is INSERT ... INTO TABLE (I did not mention in my first reply, sorry)
12-17-2008 9:48 PM
08-06-2010 10:01 AM
I got the same issue.
With this code I got ITAB_ILLEGAL_SORT_ORDER
LOOP AT from_table INTO l_from.
READ TABLE to_table INTO l_to
WITH KEY thekey = ...
BINARY SEARCH.
IF sy-subrc EQ 0.
MOVE sy-tabix TO l_index.
ADD l_from-volume TO l_to-volume.
MODIFY to_table INDEX l_index
FROM l_to
TRANSPORTING volume.
ELSE.
MOVE l_from TO l_to.
MOVE ... TO l_to-....
APPEND l_to TO to_table.
ENDIF.
ENDLOOP. " from_table
I replaced APPEND with INSERT and I got TABLE_ILLEGAL_STATEMENT
LOOP AT from_table INTO l_from.
READ TABLE to_table INTO l_to
WITH KEY thekey = ...
BINARY SEARCH.
IF sy-subrc EQ 0.
MOVE sy-tabix TO l_index.
ADD l_from-volume TO l_to-volume.
MODIFY to_table INDEX l_index
FROM l_to
TRANSPORTING volume.
ELSE.
MOVE l_from TO l_to.
MOVE ... TO l_to-....
INSERT l_to INTO to_table.
ENDIF.
ENDLOOP. " from_table
wtf ?
Help !
03-31-2015 2:35 PM