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 between like and type

Former Member
0 Likes
999

hi gurus

can anyone inform me what is the difference between like and type statements

regards,

kals.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
968

hi

good

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.

thanks

mrutyun^

7 REPLIES 7
Read only

Former Member
0 Likes
968

HI,

type describes the field 'matnr' with the dataelement defined by the user in se11.

(user can create his/her own dataelement)

for eg:

data: matnr type d_matnr.

like decribes the field 'matnr' with the help of system defined

dataelement.

for eg:

tables: mara.

data: matnr like mara-matnr.

Read only

Former Member
0 Likes
968

Hi Kalyan,

Type is used to definethe data type .

whereas Like is used to define the dataobject.

eg. data: matnr type matnr.

eg for like

data: matnr LIKE mara-matnr.

hope got the difference.

regards,

Sana.

reward points for useful answers,

Read only

Former Member
0 Likes
968

hi,

Type

By using this we can create our own data type using existing data types and we can create structures.

LIKE

This will points towards already existed or user defined data type.

for u r understanding

type : begin of st1,

name type c(10),

address type c(100),

end of st1.

data : per like st1.

if i want to have one more structure with similar data types then u have no need to redefine them

type : begin of st2,

per1 like st1,

phone like c(10),

end of st2.

cheers,

pavan

Read only

Former Member
Read only

Former Member
0 Likes
968

Hi,

Type is used to refer predefined data types, where as Like refer for user defined data types.

For example.

data:

Begin of fs_data.

c_box,

name(10) type c,

end of fs_data.

data: it_tab like table of fs_data.

whereas Type

data:

it_tab type table of mara.

Plzz reward points if it helps.

Read only

Former Member
0 Likes
969

hi

good

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.

thanks

mrutyun^

Read only

0 Likes
968

thanks a lot.

means anything in the data dictionary and activated is a available as a type.

and local types we can define.

varun