Show TOC Entering content frame

Assigning 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 internal tables. 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 list output is:

A B

The example creates two standard tables etaband ftab with the line type of the structure 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 list output is:

 1.000000000000000E+00

 2.000000000000000E+00

 3.000000000000000E+00

ftab is a sorted table with the line type f and a non-unique key. itab is a hashed table with the line type i and a unique key. The line types, and therefore all the 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 like this:

6.03823403895813E-154

6.03969074613219E-154

6.04114745330626E-154

Here, the line types of the internal tables itabund 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 itabare converted to type C fields and then written to ftab. The ABAP system interprets the transferred data as type f fields, so that the results are meaningless. In Unicode systems, you can not convert numeric fields to fields of type c.

 

Leaving content frame