Application Development and Automation 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: 
Read only

append one internal table to another..

Former Member
135,308

hi,

i have an internal table 'XX' based on a structure "s1". This contains some data. I have another similar internal table "YY". Now I want all the records from YY to be added to XX (i.e. append at the end ). what is the best code ? can some one give a sample please.

thks

1 ACCEPTED SOLUTION
Read only

Former Member
49,142

If internal tables XX and YY are of asme type S1 then you can use

append lines of yy to XX

The rows of an internal table jtab are appended according to the same rules that apply for appending a workarea, in the sequence in which they exist in jtab. If jtab is an index table, you can restrict the rows to be appended by specifying FROM idx1 and TO idx2. In this case, only the table rows starting at table index idx1 or ending at table index idx2 from jtab are appended. For idx1 and idx2, data objects of type i are expected. If the value idx1 or idx2 is less than 0, an untreatable exception occurs. If idx1 is greater than idx2 or greater than the number of table rows, no rows are appended. If idx2 is greater than the number of table rows, it is set to the number of table rows.

Example

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.

Edited by: Naren K Someneni on May 29, 2008 12:13 PM

If internal tables XX and YY are of asme type S1 then you can use

append lines of yy to XX

The rows of an internal table jtab are appended according to the same rules that apply for appending a workarea, in the sequence in which they exist in jtab. If jtab is an index table, you can restrict the rows to be appended by specifying FROM idx1 and TO idx2. In this case, only the table rows starting at table index idx1 or ending at table index idx2 from jtab are appended. For idx1 and idx2, data objects of type i are expected. If the value idx1 or idx2 is less than 0, an untreatable exception occurs. If idx1 is greater than idx2 or greater than the number of table rows, no rows are appended. If idx2 is greater than the number of table rows, it is set to the number of table rows.

Example

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.

Edited by: Naren K Someneni on May 29, 2008 12:13 PM

4 REPLIES 4
Read only

Former Member
49,143

If internal tables XX and YY are of asme type S1 then you can use

append lines of yy to XX

The rows of an internal table jtab are appended according to the same rules that apply for appending a workarea, in the sequence in which they exist in jtab. If jtab is an index table, you can restrict the rows to be appended by specifying FROM idx1 and TO idx2. In this case, only the table rows starting at table index idx1 or ending at table index idx2 from jtab are appended. For idx1 and idx2, data objects of type i are expected. If the value idx1 or idx2 is less than 0, an untreatable exception occurs. If idx1 is greater than idx2 or greater than the number of table rows, no rows are appended. If idx2 is greater than the number of table rows, it is set to the number of table rows.

Example

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.

Edited by: Naren K Someneni on May 29, 2008 12:13 PM

Read only

former_member156446
Active Contributor
0 Likes
49,142
append line of XX to YY.

or 
XX[ ] = YY[ ]
Read only

Former Member
49,142

You can do this using simple statement.

if the structure of the two internal tables are same you can simply do like this

it_table1[ ] = it_table2[ ].

if the structures are not same use move corresponding statement like this

move corresponding fields of it_table2 to it_table1

or

it_table1-field = it_table2-field.

append it_table1.

clear it_table1.

if it is useful. please reward me the points

Chinna

Edited by: Chinna on May 29, 2008 7:13 PM

Edited by: Chinna on May 29, 2008 7:13 PM

Read only

Former Member
0 Likes
49,142

u can use in a LOOP the MOVE-CORRESPONDING FIELDS xx TO yy

the fields have the same name in both tables,

or assign directly, here the name dont's matter

LOOP AT XX.

yy-code = xx-code.

yy-sum = xx-tot.

append yy.

endloop.