‎2007 Jul 10 11:38 AM
‎2007 Jul 10 11:40 AM
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
‎2007 Jul 10 11:40 AM
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.
‎2007 Jul 10 11:40 AM
‎2007 Jul 10 11:42 AM
hi,
when we declare a structure we declare it as type and when we declare an internal table we declare it as like.
‎2007 Jul 10 11:42 AM
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
‎2007 Jul 10 11:42 AM
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.
‎2007 Jul 10 11:43 AM
Hi sai,
1. When we declare a variable, with reference to some already another object,
we use LIKE.
2. Otherwise we use type.
‎2007 Jul 10 11:46 AM
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.
‎2007 Jul 10 11:46 AM
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
‎2007 Jul 10 11:50 AM
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
‎2007 Jul 10 12:07 PM
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.
‎2007 Jul 10 1:37 PM
Hi sai,
solve ur problem..
or...
use this links...
http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb2ff3358411d1829f0000e829fbfe/content.htm
for like....
http://help.sap.com/saphelp_nw04/helpdata/en/9b/239fa610de11d295390000e8353423/content.htm
If useful reward me with points.
Thanks
Sanket.
‎2007 Jul 10 1:40 PM
LIKE insurs that the variable being created will always be the same as the variable being referenced.