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

difference

Former Member
0 Likes
600

Can anybody tell the difference betwwen LIKE and TYPE

5 REPLIES 5
Read only

Former Member
0 Likes
580

Hi,

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

Read only

Former Member
0 Likes
580

hi

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

reward point if helpful.

Regards

Prajwal K .

Read only

Former Member
0 Likes
580

Here is a simple main difference ..

Type : it will allocate memory during execution (object type).

Like : it will allocate memory immediatly.

---type will improve performance.

---p is packed type wherein we can restrict decimal values.

var type p decimals 2.

---float can hold more value than packed data type

Reward if helpful.

Read only

Former Member
0 Likes
580

Hi,

data field(18) type c. "here c is a predefined 'data type'

data field type matnr . "here matnr is a 'data element'

data field like mara-matnr. "here mara-matnr is a 'data object'

'type' is used to refer a data type / data element.(ie given type is the data type of our obj)

'like' is used to refer a data obj(ie copy the data type of that obj to our obj)

Cheers,

Will.

Read only

former_member156446
Active Contributor
0 Likes
580

Hi Suguna

In short to understand just think like :

if you declare some thing with LIKE memory is taken/allocated

if you declare some thing with TYPE memory is given only at runtime.