Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Difference between Type and Like?

Former Member
0 Kudos
173

Hi friends can any one explain me in simple words wht is TYPE and LIKE.

This statements i got my ABAP help..

DATA: event_table TYPE cntl_simple_events,

event LIKE LINE OF event_table.

I want to know wht happens if i write LIKE and TYPE.

Thks

4 REPLIES 4

amit_khare
Active Contributor
0 Kudos
60

TYPE - Type is used to tell the system what is the type of data object(variable) you want to create .

LIKE: If there is already a data object declared and you want to declare a similar data object you can just refer to the previous data object using like.

Refer the link -

Regards,

Amit

uwe_schieferstein
Active Contributor
0 Kudos
60

Hello Venkat

LIKE refers to an existing variable within your program or a DDIC type.

TYPE refers to a DDIC type (including type-pool types) or other type definitions in your program but not to an existing variable definition.


DATA: event_table TYPE cntl_simple_events,  " refers to another TYPE definition
event LIKE LINE OF event_table.                    " refers to existing variable event_table

Final remark: LIKE is not allowed anymore in ABAP-Objects (except for LIKE LINE OF). Thus, always use the TYPE statement.

Regards

Uwe

Former Member
0 Kudos
60

Hi,

--> A predefined ABAP type to which you refer using the TYPE addition

--> An existing local data type in the program to which you refer using the TYPE addition

--> The data type of a local data object in the program to which you refer using the LIKE addition

--> A data type in the ABAP Dictionary to which you refer using the TYPE addition. To ensure compatibility with earlier releases, it is still possible to use the LIKE addition to refer to database tables and flat structures in the ABAP Dictionary. However, you should use the TYPE addition in new programs.

The LIKE addition takes its technical attributes from a visible data object. As a rule, you can use LIKE to refer to any object that has been declared using DATA or a similar statement, and is visible in the current context. The data object only has to have been declared. It is irrelevant whether the data object already exists in memory when you make the LIKE reference.

Please check this link

http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb2ff3358411d1829f0000e829fbfe/content.htm

Best regards,

raam

Former Member
0 Kudos
60

hi,

o 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.

o 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

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 fro m 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.

Hope this helps.