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

Diff....LIKE and TYPE

SurendarT
Explorer
0 Likes
1,128

Please tell me the Difference Between ..

LIKE and TYPE........

in ABAP COding...

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,106

After LIKE, you must specify a data object directly. For the casting, the data type of the data object is used. Within a procedure, for dobj you must not specify a completely generically typed formal parameter.

After TYPE, you can specify either a data type type directly or a character-type data object name in brackets, which must, during execution, contain the label of a data object. The data type specified after TYPE can be generic. However, you cannot specify table types or REF TO.

Please reward if helpful.

9 REPLIES 9
Read only

Former Member
0 Likes
1,106

Check out this related thread

Regards,

santosh

Read only

Former Member
0 Likes
1,106

Hi,

1.TYpe does not require memory allocation.

2.Like can occupy the memory at run time.

Regards,

Shiva.

Read only

Former Member
0 Likes
1,106

Hi

Difference between type and like;

Types: var1(20) type c.

data: var2 type var1. ( type is used bcoz var1 is defined with TYPES and it

does not occupy any memory spce.

data: var3 like var2. ( like is used here bcoz var2 is defined with DATA

so it does occupy space in memory ).

data: material like mara-matnr. ( like is used here bcoz mara-matnr is stored in memory).

type refers the existing data type

like refers the existing data object

type is for predefined data type

where as like is for usedefined datatype.

TYPE, you assign datatype directly to the data object while declaring.

LIKE,you assign the datatype of another object to the declaring data object. The datatype is referenced indirectly

Thanks and Regards

Arun Joseph

Read only

Former Member
0 Likes
1,106

Hi,

TYPE

You use the TYPE addition in various ABAP statements for defining data types and specifying the types of interface parameters or field symbols. The TYPE addition can have various meanings depending on the syntax and context.

LIKE

You use the LIKE addition, similarly to the TYP E 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.

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

type we can use to refer system defined or user defined data types and data dictionary objects..

like we will use in case of refering data dictionary objects only.

Go through the link.

http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb2ff3358411d1829f0000e829fbfe/content.htm

TYPE - Type is used to tell the system what is the type of data object(variable) you want to create .

LIKE: If there is already a data object declared and you want to declare a similar data object you can just refer to the previous data object using like.

type is generally used for declaring variables, parameters for existing data types in abap

for ex: to declare a inter value and character variable of length 10 is as,

data: i1 type i,

c1(10) type c.

like generally refers to existing data objects in abap.

for ex:

data: matnr like mara-matnr,

vbeln like vbap-vbeln.

creating variables matnr, vbeln from existing fields of tables mara, vbap.

when user creates a user defiend structure for work areas, internal tables we generally use type keyword as

types: begin of itab,

.........

.........

........

end of itab.

data: itab1 type itab occurs 0 with header line

Check this thread.

https://forums.sdn.sap.com/click.jspa?searchID=711746&messageID=2270752

https://forums.sdn.sap.com/click.jspa?searchID=711746&messageID=512214

Regards,

Satish

Read only

Former Member
0 Likes
1,107

After LIKE, you must specify a data object directly. For the casting, the data type of the data object is used. Within a procedure, for dobj you must not specify a completely generically typed formal parameter.

After TYPE, you can specify either a data type type directly or a character-type data object name in brackets, which must, during execution, contain the label of a data object. The data type specified after TYPE can be generic. However, you cannot specify table types or REF TO.

Please reward if helpful.

Read only

Former Member
0 Likes
1,106

hi check this..

type is used for the predifed and basic data types...

data: char type c ( it cannot be done with like).

data: test type mara-matnr .

like is used to refer the existing..

data: test like mara-matnr.

here like brings all the properties of matnr to the test..

regards,

venkat

Read only

Former Member
0 Likes
1,106

Hi,

*This is type definition do not hold any data its just a structure..

types : begin of itab,

f1 type c,

f2 type c,

end of itab.

Now you can use TYPE not LIKE for this because this is just a structure.defining an internal table/ DATA OBJECT

data : it_itab TYPE STANDARD TABLE OF itab. "you are using type to structures

Now another table

data ITAB2 LIKE it_itab. "you can use LIKE to data Objects

you can 't do like this

data itab2 like itab. "this is wrong

*********

type is generally used for declaring variables, parameters for existing data types in abap

for ex: to declare a inter value and character variable of length 10 is as,

data: i1 type i,

c1(10) type c.

like generally refers to existing data objects in abap.

for ex:

data: matnr like mara-matnr,

vbeln like vbap-vbeln.

creating variables matnr, vbeln from existing fields of tables mara, vbap.

when user creates a user defiend structure for work areas, internal tables we generally use type keyword as

types: begin of itab,

.........

.........

........

end of itab.

data: itab1 type itab occurs 0 with header line

.............

*********

Go through the link.

http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb2ff3358411d1829f0000e829fbfe/content.htm

TYPE - Type is used to tell the system what is the type of data object(variable) you want to create .

LIKE: If there is already a data object declared and you want to declare a similar data object you can just refer to the previous data object using like.

Check this thread.

https://forums.sdn.sap.com/click.jspa?searchID=711746&messageID=2270752

https://forums.sdn.sap.com/click.jspa?searchID=711746&messageID=512214

Regards

Kiran Sure

Read only

Former Member
0 Likes
1,106

Hi,

Have a look

TYPE, you assign datatype directly to the data object while declaring.

LIKE,you assign the datatype of another object to the declaring data object. The datatype is referenced indirectly.

Type is a keyword used to refer to a data type whereas Like is a keyword used to copy the existing properties of already existing data object.

type refers the existing data type

like refers the existing data object

Reward,if useful.

Thanks,

Chandu

Read only

0 Likes
1,106

Hi

Kindly clse the thread once you got the answer.

Thanks and Regards

Arun Joseph