‎2007 Jun 11 6:40 AM
hi friends, can any one tell me the difference between type and like statements with some examples
‎2007 Jun 11 6:44 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...
‎2007 Jun 11 6:44 AM
Hi,
if you are writing.
types: begin of itab,
ekko like ekko-ekorg,
end of itab.
there is no need of declaration tables: ekko, befor this statement.
but if you are using,
types: begin of itab,
ekko type ekko-ekorg,
end of itab.
it is must to declare tables: ekko before this statement.
regards,
Ruchika
‎2007 Jun 11 6:44 AM
Hi,
If you are refering to a Data object use LIKE
And if you are refering to a Data type use TYPE
You can create a variable that inherits exactly the same technical attributes as an existing data type or data object as follows:
DATA <f> [TYPE <type>|LIKE <obj>]...
If you use the TYPE addition, <type> is any data type with fully-specified technical attributes. This can be a:
Non-generic predefined ABAP type (D, F, I, T, STRING, XSTRING)
Any existing local data type in the program.
Any ABAP Dictionary data type
If you use the LIKE addition, <obj> is a data object that has already been declared. This can also be a predefined data object. The variable <f> adopts the same technical attributes as the data object <obj>. You can also use LIKE to refer to a line of an internal table that has already been declared as a data object:
DATA <f> LIKE LINE OF <itab>.
To ensure compatibility with previous releases, <obj> can also be a database table, a view, a structure, or a component of a structure from the ABAP Dictionary.
The data types to which you refer can be elementary types, reference types, or complex types (structures or tables). For elementary field types, the variables are a single field in memory. When you declare a data type with fixed length (D, F, I, T) the system fixes the amount of memory that will be assigned. When you declare an object with a variable length (STRING, XSRTING), the system only assigns enough memory to administer the object. The length of the data object is managed dynamically at runtime. For structures, the variables are a sequence of variables, which may themselves also be included in further complex structures. The individual components take their name <ci> from the type <type> or object <obj>, and can be addressed using <f>-<c i> For tables, the memory contains administration entries that can be filled dynamically at runtime.
Diff bn TYPE N LIKE.
Go through the link.
http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb2ff3358411d1829f0000e829fbfe/content.htm
Rgds,
Priyanka.
‎2007 Jun 11 6:44 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...
‎2007 Jun 11 6:48 AM
HI, check out this
error free
data: am type bsik-dmbtr value ' 34.44'.
data: bm like am.
write: am , / bm.
bm = am.
write:/ bm.
error will be there
data: am type bsik-dmbtr value ' 34.44'.
data: bm type am. " here it will check in se11 data element for am
but there is no data element with the name " am ".
write: am , / bm.
bm = am.
write:/ bm.
regards,
venkatesh
‎2007 Jun 11 6:52 AM
Hi Arun,
'Type' is used to refer to any data type that is already known at this point in the program.
Examples: The data object <f> has a data type corresponding to the type <type>.
DATA <f> TYPE <type>.
CLASS-DATA <f> TYPE <type>.
CONSTANTS <f> TYPE <type>.
STATICS <f> TYPE <type>.
PARAMETERS <f> TYPE <type>.
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.
Examples: The data object <f> inherits all of the technical attributes of the data object <obj>.
DATA <f> LIKE <obj>.
CLASS-DATA <f> LIKE <obj>.
CONSTANTS <f> LIKE <obj>.
STATICS <f> LIKE <obj>.
PARAMETERS <f> LIKE <obj>.
Go through the link:
http://help.sap.com/saphelp_nw04/helpdata/en/9b/239fa610de11d295390000e8353423/frameset.htm
Reward points if helpful.
Regards,
Renuka.
‎2007 Jun 11 6:55 AM
Hi,
Of late is is being said that we shouldn't be using LIKE for declaring the data objects. I can think of two reasons -
1. It is very natural that a variable should have a type. This is true in many programming languages. We say that a particular variable (data object) is of a certain type. For example, in SDN, when somebody has posted a question in this forum regarding some problem he's facing, we always ask him what is the type of a certain variable in his code.
2. The like keyword presupposes the existence of a data object. Although declarations like
data work_area like spfli.
are supported, they are not considered proper usage of the LIKE keyword.
Now, when you declare a variable VAR1 which is like another variable VAR2, the data type of VAR1 is going to be dependent on the data type of VAR2. In other words, VAR1 does not have a type of its own. It acquires the type of anoher variable VAR2. If sometime later you would want to change the data type of VAR2 to something else, you cannot do so without affecting other variables which are declared like VAR2.
If each variable had its own type it is somewhat simpler to cange the data types of the variables more easily without having any cascading effects.
A DDIC object is subject to far lesser changes than a program variable. Besides, a variable that is declared using the TYPE addition and refers to a DDIC object slightly helps in static binding, which is desirable in many cases.
Regards
‎2007 Jun 11 6:57 AM
Hi,
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.
<b>1. TYPE addition</b>
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.
<b>2. The LIKE addition</b>
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 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.
e.g.
DATA: g_type TYPE EKKO.
DATA: g_like LIKE g_type.
Regards,
Yogitha
‎2007 Jun 11 7:04 AM
hi arun,
LIKE : this keyword is used for declaring data for existing data objects
for ex: data objects may be database tabels, views, structures, system variables like [sy-lsind, sy-lisel, sy-datum,...............], type pools, type groups................
ex: data: matnr like mara-matnr,
itab like ekko occurs 0 with header linr,
stru like zstru,
ok_code like sy-ucomm.
LIKE keyword mainly useful for creating a reference of existing sap data objects as variables.
TYPE: this keyword is used for creating standard data type
for ex: integer, float, time, date, pack, numeric, ..............
data: int1(2) type i value 99,
char(12) type c value 'suresh babu',
dat(10) type d,
time1(8) type t.
TYPE keyword is used to create variables with respect to sap data type.
if helpful reward some points.
with regards,
suresh.