Application Development and Automation 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: 
Read only

difference between like and type

Former Member
0 Likes
1,454

difference between like and type and when to use what

13 REPLIES 13
Read only

former_member196299
Active Contributor
0 Likes
1,219

hi Sai ,

Here you go :

Difference TYPE VS LIKE

difference inusing LIKE and TYPE

For all practical purpose, they are same.

When we declare a variable, with refernce to some object in memory,

we use LIKE.

for pre-defined types, we use type eg. C, N, etc.

2.Using which one is better

There is no difference, better wise.

3. Which will improve the performance

Both are same. Both finally create a variable only.

Reward if helpful !

Regards,

Ranjita

Read only

Former Member
0 Likes
1,219

Hi Sai,

ABAP distinguishes between types and objects. Types are descriptions that do not occupy memory. Objects are instances of types, and do occupy their own memory space. A type describes the technical attributes of all of the objects with that type.

You can use the addition

TYPE <type>

to refer to any data type <type> that is already known at this point in the program.

DATA <f> TYPE <type>.

The data object <f> has a data type corresponding to the type <type>.

DATA <f> LIKE <obj>.

The data object <f> inherits all of the technical attributes of the data object <obj>.

Take an example :

types : begin of ty_tab,

name(30),

pwd(10),

end of ty_tab.

data : itab like ty_tab.

See here we declared the structure of ty_tab, which do not occupy memory. So if we run this, we will get compile time error like this : Field TY_TAB is unknown. It is neither in one of the specified tables nor defined by a DATA statement.

So in this case u need to correct the error with "TYPE" statement...like this.

types : begin of ty_tab,

name(30),

pwd(10),

end of ty_tab.

data : itab type ty_tab.

Refer these

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

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

Thanks.

reward If helpful.

Read only

amit_khare
Active Contributor
0 Likes
1,219

Refer the links -

Regards,

Amit

Reward all helpful replies.

Read only

Former Member
0 Likes
1,219

hi,

when we declare a structure we declare it as type and when we declare an internal table we declare it as like.

Read only

Former Member
0 Likes
1,219

Hi,

LIKE is used inorder to refer to a present object and to have the semantic definition of that object that is being refered to.

TYPE is used in declaring the object using an elementary data type or a data element which has the same semantic definition that is required.

It is good practice to use TYPE as much as possible when there is a possibility to avoid LIKE.

<b>

Reward points if this is helpful,</b>

Kiran

Read only

Former Member
0 Likes
1,219

Hi,

I think they are the same.

But it is suggested to use TYPE instead of LIKE since SAP now mark it as obsolete statement.

Read only

Former Member
0 Likes
1,219

Hi sai,

1. When we declare a variable, with reference to some already another object,

we use LIKE.

2. Otherwise we use type.

Read only

Former Member
0 Likes
1,219

hi

TYPE

You use the TYPE addition in various ABAP statements for defining data types and specifying the types of interface parameters or field symbols. The TYPE addition can have various meanings depending on the syntax and context.

LIKE

You use the LIKE addition, similarly to the TYPE addition , in various ABAP statements for defining data types and specifying the types of interface parameters or field symbols.

it can be used in the same ABAP statements as the TYPE addition to refer to any data object <obj> that is already visible at that point in the program. The expression <obj> is either the name of the data object or the expression.

You use LIKE to make the new object or type inherit the technical attributes of an existing data object.

reward if useful.

Read only

Former Member
0 Likes
1,219

Hi,

<u><b>The LIKE Addition:</b></u>

You use the LIKE addition, similarly to the TYPE addition, in various ABAP statements for defining data types and specifying the types of interface parameters or field symbols. The addition

LIKE <obj>

can be used in the same ABAP statements as the TYPE addition to refer to any data object <obj> that is already visible at that point in the program. The expression <obj> is either the name of the data object or the expression

LINE OF <table-object>

In this case, the LIKE addition describes the line type of a table object that is visible at that point in the program.

You use LIKE to make the new object or type inherit the technical attributes of an existing data object.

<u><b>The TYPE Addition:</b></u>

You use the TYPE addition in various ABAP statements for defining data types and specifying the types of interface parameters or field symbols. The TYPE addition can have various meanings depending on the syntax and context.

Referring to Known Data Types You can use the addition

TYPE <type> to refer to any data type <type> that is already known at this point in the program. It can be used in any of the statements listed below. The expression <obj> is either the name of the data object or the expression

LINE OF <table-type> In this case, the TYPE addition describes the line type of a table type <table-type> that is visible at that point in the program.

Regards,

Bhaskar

Read only

Former Member
0 Likes
1,219

hi sai,

type: generally used for creating variables, objects for existing data types

i.e i,n,c, s .............

data: int type i,

chara type c.

like: mainly useful for refering to existing to data objects that are available in sap.

ex:

data: itab like mara occurs 0 with header line.

both are same in some cases but when we used types keyword for creating user defined structures in those cases we must use type and not like keyword.

ex:

types: begin of itab,

matnr like mara-matnr,

mtart like mara-mtart.

end of itab.

data: jtab type [not like] itab ocuurs 0 with header line.

if helpful reward some points.

with regards,

Suresh.A

Read only

Former Member
0 Likes
1,219

Hi sai,

The declaration with TYPE is used with custom defined data types or predefined

ABAP types.

where LIKE addition for data declaration is used with Data objects like tables, line types and internal table types.

There will not be any performance issues if you use type or like.

Hope this will help u.

Thanks,

Vijay.

Reward points if its helpful in any way.

Read only

Former Member
0 Likes
1,219
Read only

Former Member
0 Likes
1,219

LIKE insurs that the variable being created will always be the same as the variable being referenced.