You are on page 1of 2

Note 176337 Note Language: English

On the difference between TYPE and LIKE


Version: 7 Validity:
Valid from 04.10.1999

Summary
Symptom
This is an explanation of differences between TYPE and LIKE additions

Additional key words


Data types, data objects, ABAP type concept, Dictionary reference

Cause and prerequisites


The ABAP type concept distinguishes between data types and data objects. o Data types are either defined locally in an ABAP program with TYPES or globally in the ABAP Dictionary. Data objects reside in the internal mode of an ABAP program and are declared prototypical with the statement DATA.

When you declare local program data types with TYPES or data objects with DATA, the data type must be defined. To do this you can refer to already existing types in addition to using type constructors, for example, TYPE TABLE OF or TYPE REF TO. It is possible to refer to data types using the TYPE addition and the data object using the LIKE addition. Furthermore, type references are possible using TYPE and LIKE also during typing interface parameters or field symbols.

TYPE addition With TYPE addition, you can refer either to local data types of the same ABAP program or on global data types of the Dictionaries. Local types mask global types that have the same names. When typing the interface parameters or field symbols, a reference is also possible to generic types ANY, ANY TABLE,INDEX TABLE, TABLE or STANDARD TABLE, SORTED TABLE and HASHED TABLE.

The LIKE addition With the LIKE addition, you can refer to all visible data objects at the ABAP program's positon in question. Only the declaration of the data object must be known. In this case it is totally irrelevant whether the data object already exists physically in memory during the LIKE reference. Local data objects mask global data objects that have the same name.

The semantic separation between data types and data objects is reflected by the syntactic separation in ABAP between TYPE and LIKE. This separation allows for separate namespaces for data types and data objects. Only for reasons of compatibility with preceding releases, can you refer to flat structures (see note 176336) in the ABAP Dictionary with the LIKE addition, so to database tables and independent flat structures. The LIKE addition first finds a data object on the local program and then in the ABAP Dictionary it finds a database table or flat structure that has the same name. The type reference on the ABAP Dictionary is no longer possible with LIKE in the class of ABAP objects. In all ABAP programs, the LIKE reference
25.06.2007 Page 1 of 2

Note 176337 -

On the difference between TYPE and LIKE

is forbidden on data elements, internal tables and deep structures of the ABAP Dictionary. The TYPE reference to global data types of the ABAP Dictionary is possible as of Release 4.5. At the same time all types of the ABAP type concept can be defined in the ABAP Dictionary as of Release 4.5. Previously there was only an actual equivalent for flat structures between the ABAP data types and the dictionary data types. The structure of database tables and independent structures corresponded to the ABAP data type structure in the dictionary Only with the LIKE addition could database tables and structures be referred to from ABAP programs. In the meantime the LIKE addition should be used in all ABAP programs only for referring to data objects while the TYPE addition is used of the reference to the data type. Caution should be taken if a flat structure is changed in the dictionary by adding or changing a component into a deep structure. Then a reference with the LIKE reference is syntactically no longer possible and the ABAP programs must be changed appropriately. As outlined in Note 176336, such a structure change means more than replacing the LIKE with the TYPE addition. Moreover the use of the structure must also be checked at other positions.

Solution
See Note

Source code corrections

Header Data
Release Status: Released on: Priority: Category: Main Component Released for Customer 03.10.1999 22:00:00 Recommendations/additional info Consulting BC-ABA-LA Syntax, Compiler, Runtime

The note is not release-dependent.

Related Notes
Number 176336 Short Text Flat and deep structures in ABAP

25.06.2007

Page 2 of 2