Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Assignments →  Assignment and Conversion Rules 

Conversion Rules for Internal Tables

Internal tables can only be assigned to internal tables. Whether or not assignment is possible depends exclusively on row type, and is independent of table type, table key, and number of rows. Internal tables can be assigned to each other if their row types are compatible or convertible.

When assigning an internal table to another, the rows of the target table are deleted. A new row is created in the target table for each row in the source table. They are then filled with the row contents in the source table. The rows are stored according to the table category. For assignments to a sorted table, the content is automatically sorted and hashed tables are stored according to the hash algorithm.

The content of the individual rows in the source table is assigned to the rows in the target table according to the same rules as for assignments between individual data objects of corresponding row types. The same basic rule as for all conversions applies: The converted content of the single rows in the source table must lie within the value range of the row type in the target table.

Other versions: 7.31 | 7.40 | 7.54


Notes

  • In internal tables with compatible or convertible row types, a non-handleable exception can be raised during assignment if, for example, in the target table a duplicate of a unique primary table key or secondary table key is created.

  • Internal tables with elementary row types can raise the same handleable exceptions as when making assignments between the associated elementary data types. After an exception of this type, all rows assigned until this point are passed to the target table.

  • In assignments of an initial internal table to a filled internal table, the target table is initialized in the same way as with the statement CLEAR. This frees up the memory space required for the table, except for the initial memory requirement (see INITIAL SIZE).

Programming Guideline

Avoid unexpected conversion results


Example

A standard table text_tab with row type c of length 20 is converted to a sorted table of type string.

TYPES: 
  text TYPE c LENGTH 20. 
DATA: 
  text_tab   TYPE STANDARD TABLE OF text WITH EMPTY KEY, 
  string_tab TYPE SORTED TABLE OF string WITH NON-UNIQUE KEY table_line. 

text_tab = VALUE #( 
  ( 'Perl' ) ( 'C' ) ( 'Visual Basic' ) ( 'Java' ) 
  ( 'ABAP' ) ( 'Pascal' ) ( 'Python' )  ( 'Lisp' ) ). 

string_tab = text_tab. 

cl_demo_output=>new( )->write( text_tab )->display( string_tab ).