2007 Dec 10 1:34 PM
What is the exact difference betwn TYPE and LIKE?Explain with an example.
Where to use exactly?Sometimes it dislays errors.
What is the exact difference betwn TYPE and LIKE?Explain with an example.
Where to use exactly?Sometimes it dislays errors.
2007 Dec 10 1:38 PM
Now ABAP is Object Oriented, so SAP has recommended to use TYPE instead of using LIKE.
But you can still use LIKE, but it will show you warnings in the extended program check.
Regards,
Satish
2007 Dec 10 1:39 PM
TYPE refers directly to the kind of data that the field is. LIKE says "this data is like this other data". Like is used to attach a bit of context and meaning to your code, but otherwise it makes no difference.
DATA: l_mandt TYPE mandt.
and
DATA: l_mandt TYPE sy-mandt.
Behave the same.
If you are getting errors, that's probably because you're not using the syntax exactly right. What errors are you getting?
matt
2007 Dec 10 1:40 PM
type is for ddic references. you can use Type only when you got a type to reference.
while with like you reference to the type of a runtime object.
try to use type wherever you can, there´s no need for like.
It just makes things more easy sometimes.
e.G.:
data: ls_vbak type vbak,
ls_vbak2 like ls_vbak.
while
data ls_vbak like vbak.
shouldnt work since vbak is a transparent table but no runtime object.
The problem in understanding this thing is that it will work as well with like here in last example.
2007 Dec 10 1:40 PM
2007 Dec 10 1:49 PM
hi
good
Here is what the ABAP keyword documentation says to:
DATA - TYPE, LIKE
In the specification of a data type type or a data object dobj, the data type of the variable dobj is already fully defined before the declaration. The syntax and meaning of the additions TYPE and LIKE has exactly the same meaning as the definition of data types with TYPES, except that for DATA after TYPE a standard table type with a generic table key can be specified. In this case, a bound table type with a standard key is created.
However, with respect to ABAP-OO you should favour DATA ... TYPE ... because within classes and interfaces you can only use TYPE to refer to dictionary types.
thanks
mrutyun^
2007 Dec 10 1:50 PM
Hi khanna,
1. What is the exact difference betwn TYPE and LIKE
For practical purpose, there is no difference.
Only the syntax is different.
The end result is the same.
2.
type = when we want to declare for some type of data
like = when we want to declare with some varible/object which is already there.
3.
data : a type bukrs. <----
bukrs data element is considered
data : b like t001-bukrs. <----
the actual field -->its kind/type is considered
regards,
amit m.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |