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

Type and Like

Former Member
0 Likes
800

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.

6 REPLIES 6
Read only

Former Member
0 Likes
758

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

Read only

matt
Active Contributor
0 Likes
758

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

Read only

Former Member
0 Likes
758

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.

Read only

Former Member
0 Likes
758

Have a look at this thread. This topic is fully discussed there with examples.

Hope this helps.

Amandeep

Read only

Former Member
0 Likes
758

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^

Read only

Former Member
0 Likes
758

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.