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

like vs type

Former Member
0 Likes
1,077

Hi,

what is the difference between like and type? & how come in OO context can't use like?

Thanks,

Charles

abap newbie

1 ACCEPTED SOLUTION
Read only

SantoshKallem
Active Contributor
0 Likes
1,047

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...

12 REPLIES 12
Read only

SantoshKallem
Active Contributor
0 Likes
1,048

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...

Read only

amit_khare
Active Contributor
0 Likes
1,047

Hi,

refer to this link.

<a href="http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb2ff3358411d1829f0000e829fbfe/frameset.htm">Like vs Type</a>

Regards,

Amit

Read only

Former Member
0 Likes
1,047

Hi,

Refer the Thread

Type, Types, Data, Like

Rgds,

Prakash

Read only

anversha_s
Active Contributor
0 Likes
1,047

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...

Regards

Anver

Read only

Former Member
0 Likes
1,047

TYPE:

You use the 'TYPE' in various ABAP statements for defining data types and specifying the types of interface parameters or field symbols.

The TYPE addition allows you to construct new data types in the TYPES, DATA; CONSTANTS;and STATICS statements. In the TYPES statement, these are local data types in the program. In the other statements, they are attributes of new data objects.

• Definition of local program types using

TYPES <t> TYPE <type>.

The new data type <t> has the same type as <type>.

• Declaration of data objects using

DATA <f> TYPE <type>.

CLASS-DATA <f> TYPE <type>.

CONSTANTS <f> TYPE <type>.

STATICS <f> TYPE <type>.

PARAMETERS <f> TYPE <type>.

The data object <f> has a data type corresponding to the type <type>.

• Dynamic creation of data objects using

CREATE DATA <dref> TYPE <type>.

• Specification of the type of a formal parameter in a subroutine using

FORM <sub> ... USING|CHANGING <p> TYPE <type> ...

The technical attributes of the formal parameter <p> are inherited from those of the

declared data type <type>. You can then only pass actual parameters that have these attributes.

• Specification of the type of a formal parameter in a method using

METHODS <meth> ... IMPORTING|EXPORTING|CHANGING <p> TYPE <type>

LIKE:

You use the LIKE, similarly to the TYPE addition, in various ABAP statements for

defining data types and specifying the types of interface parameters or field symbols. The addition 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 LINE OF <table-object>

In this case, the LIKE addition describes the line type of a table object that is visible at that point in the program.

You use LIKE to make the new object or type inherit the technical attributes of an existing data object.

• Definition of local types in a program using

TYPES <t> LIKE <obj>.

The new data type <t> inherits all of the technical attributes of the data object <obj>.

• Declaration of data objects using

DATA <f> LIKE <obj>.

CLASS-DATA <f> LIKE <obj>.

CONSTANTS <f> LIKE <obj>.

STATICS <f> LIKE <obj>.

PARAMETERS <f> LIKE <obj>.

The data object <f> inherits all of the technical attributes of the data object <obj>.

• Dynamic creation of data objects using

CREATE DATA <dref> LIKE <obj>.

• Specification of the type of a formal parameter in a subroutine using

FORM <sub> ... USING|CHANGING <p> LIKE <obj> ...

The technical attributes of the formal parameter <p> are inherited from those of the

declared data object <obj>. You can then only pass actual parameters that have these attributes.

Read only

Former Member
0 Likes
1,047

so how come in OO, can't use like?

Read only

Former Member
0 Likes
1,047

hi,

like is indirectly addressed to the existing data object where as type is directly addressed to the existing data type .

Read only

Former Member
0 Likes
1,047

so how come in OO,

only type is supported and not like?????

Read only

0 Likes
1,047

Hi Charles,

Can you just give me an example where you would want to use 'LIKE; in ABAP Objects?

We use only the 'TYPE REF TO' to define abap objects.

Regards,

Sharadha

Read only

0 Likes
1,047

eg.

data: matnr like mara-matnr.

Read only

0 Likes
1,047

Hi Charles,

You should use "TYPE" to refer ABAP dictionary types and you can use "LIKE" to refer local data objects.

Regards,

Sharadha

Read only

0 Likes
1,047

i thought should be the opposite?

use like for data dictionary objects and type for locally declared objects?