‎2006 Dec 27 7:24 AM
Hi,
what is the difference between like and type? & how come in OO context can't use like?
Thanks,
Charles
abap newbie
‎2006 Dec 27 7:29 AM
LIKE means the datatype of the variable is similar to the referenced variable.
TYPE means it is a predefined data type.
Eg:
DATA int TYPE i.
Here int is of integer data type.
DATA var LIKE int.
var IS a variable having same data type of int. which in turn is integer.
You can find these helpful when you reference database table variables... You need not know what is the datatype defined.
Also it adds to FLEXIBILITY.
Whenever you make changes to your database tables and fields,
that change is REFLECTED back to your program that is,
You need not change all your program code when you change your table fields...
‎2006 Dec 27 7:29 AM
LIKE means the datatype of the variable is similar to the referenced variable.
TYPE means it is a predefined data type.
Eg:
DATA int TYPE i.
Here int is of integer data type.
DATA var LIKE int.
var IS a variable having same data type of int. which in turn is integer.
You can find these helpful when you reference database table variables... You need not know what is the datatype defined.
Also it adds to FLEXIBILITY.
Whenever you make changes to your database tables and fields,
that change is REFLECTED back to your program that is,
You need not change all your program code when you change your table fields...
‎2006 Dec 27 7:31 AM
Hi,
refer to this link.
<a href="http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb2ff3358411d1829f0000e829fbfe/frameset.htm">Like vs Type</a>
Regards,
Amit
‎2006 Dec 27 7:32 AM
‎2006 Dec 27 7:35 AM
hi,
http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb2ff3358411d1829f0000e829fbfe/frameset.htm
For TYPE
http://help.sap.com/saphelp_47x200/helpdata/en/d3/2e974d35c511d1829f0000e829fbfe/frameset.htm
For LIKE
http://help.sap.com/saphelp_47x200/helpdata/en/d3/2e974d35c511d1829f0000e829fbfe/frameset.htm
http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb367a358411d1829f0000e829fbfe/content.htm
LIKE means the datatype of the variable is similar to the referenced variable.
TYPE means it is a predefined data type.
Eg:
DATA int TYPE i.
Here int is of integer data type.
DATA var LIKE int.
var IS a variable having same data type of int. which in turn is integer.
You can find these helpful when you reference database table variables... You need not know what is the datatype defined.
Also it adds to FLEXIBILITY.
Whenever you make changes to your database tables and fields,
that change is REFLECTED back to your program that is,
You need not change all your program code when you change your table fields...
Regards
Anver
‎2006 Dec 27 7:37 AM
TYPE:
You use the 'TYPE' in various ABAP statements for defining data types and specifying the types of interface parameters or field symbols.
The TYPE addition allows you to construct new data types in the TYPES, DATA; CONSTANTS;and STATICS statements. In the TYPES statement, these are local data types in the program. In the other statements, they are attributes of new data objects.
Definition of local program types using
TYPES <t> TYPE <type>.
The new data type <t> has the same type as <type>.
Declaration of data objects using
DATA <f> TYPE <type>.
CLASS-DATA <f> TYPE <type>.
CONSTANTS <f> TYPE <type>.
STATICS <f> TYPE <type>.
PARAMETERS <f> TYPE <type>.
The data object <f> has a data type corresponding to the type <type>.
Dynamic creation of data objects using
CREATE DATA <dref> TYPE <type>.
Specification of the type of a formal parameter in a subroutine using
FORM <sub> ... USING|CHANGING <p> TYPE <type> ...
The technical attributes of the formal parameter <p> are inherited from those of the
declared data type <type>. You can then only pass actual parameters that have these attributes.
Specification of the type of a formal parameter in a method using
METHODS <meth> ... IMPORTING|EXPORTING|CHANGING <p> TYPE <type>
LIKE:
You use the LIKE, 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.
Definition of local types in a program using
TYPES <t> LIKE <obj>.
The new data type <t> inherits all of the technical attributes of the data object <obj>.
Declaration of data objects using
DATA <f> LIKE <obj>.
CLASS-DATA <f> LIKE <obj>.
CONSTANTS <f> LIKE <obj>.
STATICS <f> LIKE <obj>.
PARAMETERS <f> LIKE <obj>.
The data object <f> inherits all of the technical attributes of the data object <obj>.
Dynamic creation of data objects using
CREATE DATA <dref> LIKE <obj>.
Specification of the type of a formal parameter in a subroutine using
FORM <sub> ... USING|CHANGING <p> LIKE <obj> ...
The technical attributes of the formal parameter <p> are inherited from those of the
declared data object <obj>. You can then only pass actual parameters that have these attributes.
‎2006 Dec 27 7:44 AM
‎2006 Dec 27 7:53 AM
hi,
like is indirectly addressed to the existing data object where as type is directly addressed to the existing data type .
‎2006 Dec 27 9:51 AM
‎2006 Dec 27 9:59 AM
Hi Charles,
Can you just give me an example where you would want to use 'LIKE; in ABAP Objects?
We use only the 'TYPE REF TO' to define abap objects.
Regards,
Sharadha
‎2006 Dec 27 10:04 AM
‎2006 Dec 27 10:24 AM
Hi Charles,
You should use "TYPE" to refer ABAP dictionary types and you can use "LIKE" to refer local data objects.
Regards,
Sharadha
‎2006 Dec 28 9:41 AM
i thought should be the opposite?
use like for data dictionary objects and type for locally declared objects?