Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

APPEND LINES - with sorted table?

Former Member
0 Kudos

Hi there,

how can I use the APPEND LINES statment with sorted tables? Is this possible???

Kind regards

Max

1 ACCEPTED SOLUTION

former_member181995
Active Contributor
0 Kudos

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.

9 REPLIES 9

Former Member
0 Kudos

You should use the INSERT command.

former_member181995
Active Contributor
0 Kudos

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.

0 Kudos

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.

0 Kudos

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

0 Kudos

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.

0 Kudos

>

> 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)

0 Kudos

Yes

0 Kudos

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 !

0 Kudos

This message was moderated.