Assigning Internal Tables 

Like other data objects, you can make internal tables operands in the MOVE statement

MOVE <itab1> TO <itab2>.

or the equivalent statement

<itab2> = <itab1>.

Both operands must either be compatible or convertible. These statements assign the entire contents of table <itab1> to table <itab2>, including the data in any nested internal tables. The original contents of the target table are overwritten.

If you are using internal tables with header lines, remember that the header line and the body of the table have the same name. If you want to address the body of the table in an assignment, you must place two brackets ([ ]) after the table name.

DATA: BEGIN OF LINE,
        COL1,
        COL2,
      END OF LINE.

DATA: ETAB LIKE TABLE OF LINE WITH HEADER LINE,
      FTAB LIKE TABLE OF LINE.

LINE-COL1 = 'A'. LINE-COL2 = 'B'.

APPEND LINE TO ETAB.

MOVE ETAB[] TO FTAB.

LOOP AT FTAB INTO LINE.
  WRITE: / LINE-COL1, LINE-COL2.
ENDLOOP.

The output is:

A B

The example creates two standard tables ETAB and FTAB with the line type of the structure LINE. ETAB has a header line. After filling ETAB line by line using the APPEND statement, its entire contents are assigned to FTAB. Note the brackets in the statement.

DATA: FTAB TYPE SORTED TABLE OF F
WITH NON-UNIQUE KEY TABLE LINE,
ITAB TYPE HASHED TABLE OF I
WITH UNIQUE KEY TABLE LINE,
FL TYPE F.

DO 3 TIMES.
INSERT SY-INDEX INTO TABLE ITAB.
ENDDO.

FTAB = ITAB.

LOOP AT FTAB INTO FL.
WRITE: / FL.
ENDLOOP.

The output is:

1.000000000000000E+00

2.000000000000000E+00

3.000000000000000E+00

FTAB is a sorted table with line type F and a non-unique key. ITAB is a hashed table with line type I and a unique key. The line types, and therefore the entire tables, are convertible. It is therefore possible to assign the contents of ITAB to FTAB. When you assign the unsorted table ITAB to the sorted table FTAB, the contents are automatically sorted by the key of FTAB.

DATA: BEGIN OF ILINE,
NUM TYPE I,
END OF ILINE,

BEGIN OF FLINE,
NUM TYPE F,
END OF FLINE,

ITAB LIKE TABLE OF ILINE,
FTAB LIKE TABLE OF FLINE.

DO 3 TIMES.
ILINE-NUM = SY-INDEX.
APPEND ILINE-NUM TO ITAB.
ENDDO.

FTAB = ITAB.

LOOP AT FTAB INTO FLINE.
WRITE: / FLINE-NUM.
ENDLOOP.

The output might look like this:

6.03823403895813E-154

6.03969074613219E-154

6.04114745330626E-154

Here, the line types of the internal tables ITAB and FTAB are structures each with one component of type I or F. The line types are convertible, but not compatible. Therefore, when assigning ITAB to FTAB, the contents of Table ITAB are converted to type C fields and then written to FTAB. The system interprets the transferred data as type F fields, and obtains meaningless results.