Entering content frameAssigning Internal Tables Locate the document in its SAP Library structure

Like other data objects, you can use internal tables as operands in a 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.

Example

DATA: BEGIN OF line,
        col1(1) TYPE c,
        col2(1) TYPE c,
      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.

Example

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.

Example

In Unicode systems, the following conversion is not allowed:

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.

In a non-Unicode system, the output may look something 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, so that the results are meaningless. In Unicode systems, you are not allowed to convert numeric fields to fields of type C.

Leaving content frame