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 v/s LIKE

Former Member
0 Likes
1,450

Hi,

I have a question on TYPE...

what TYPE offer that LIKE does't ?

can we use LIKE any where where TYPE is used?

Thanks & Regards

Mahesh.

1 ACCEPTED SOLUTION
Read only

p291102
Active Contributor
0 Likes
1,409

Hi,

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

Thanks,

Shankar

Hi,

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

Thanks,

Shankar

14 REPLIES 14
Read only

Former Member
0 Likes
1,409

Hi,

You can data element using type statement..But you cannot use data element in LIKE statement..You cannot use table type created in ddic..

<b>You cannot use</b>

DATA: V_MATNR LIKE MATNR.

DATA: V_TABLETYPE LIKE BSEG_T.

<b>Can be used.</b>

DATA: V_MATNR TYPE MATNR.

DATA: V_TABLETYPE TYPE BSEG_T.

Thanks,

Naren

Read only

0 Likes
1,409

Hi Naren,

Thanks for ur reply,

Can U explain at Memory level how these two works? (LIKE and TYPE)

Thanks and Regards

Mahesh.

Read only

former_member188827
Active Contributor
0 Likes
1,409

hi

type is used for data types defined in dictionary and like is used to refer to data type of variable already defined in program.

Read only

Former Member
0 Likes
1,409

Hi,

Type refer to data type

like refer to existing variable.

Read only

Former Member
0 Likes
1,409

Hi

DATA - TYPE, LIKE

Syntax

DATA dobj { {TYPE [LINE OF] type}

| {LIKE [LINE OF] dobj} }

[VALUE val|{IS INITIAL}]

[READ-ONLY].

Effect

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.

Prior to Release 6.10, no VALUE addition was possible if the data type deep, specified using TYPE or LIKE, was a string, a reference type, a table type, or a structured type with deep components. As of Release 6.10, the VALUE addition can also be used for deep data types; however, with the limitation that a start value val can only be specified for the ABAP type string, and otherwise only IS INITIAL.

Example

These statements define two data objects, both of which have the same data type as the database table spfli.

DATA: spfli_wa1 TYPE spfli,

spfli_wa2 LIKE spfli_wa1.

regards

Shiva

Read only

p291102
Active Contributor
0 Likes
1,410

Hi,

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

Thanks,

Shankar

Read only

Former Member
0 Likes
1,409

Hi..

TYPE can be used in place of like..

Please see these examples..

DATA : t TYPE kna1-kunnr. " correct

DATA : r LIKE kna1-kunnr. " correct

DATA : l_var TYPE c. " correct

DATA : y_var LIKE c. "error..

DATA : u_var LIKE l_var. " correct

I declred u_var as a LIKE of l_var..I

but l_var is initilly a TYPE of C..

So.. u can use LIKE when u r declaring it against a type data that is already existing..

Hope its clear..

Mark if useful

Rajiv

Read only

Former Member
0 Likes
1,409

HI Mahesh,

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

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

Definition of local program types using

TYPES <t> TYPE <type>.

Definition of local types in a program using

TYPES <t> LIKE <obj>.

Regards

Sudheer

Read only

Former Member
0 Likes
1,409

HI Mahesh ,

DATA dobj { {TYPE [LINE OF] type}

| {LIKE [LINE OF] dobj} }

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.

Prior to Release 6.10, no VALUE addition was possible if the data type deep, specified using TYPE or LIKE, was a string, a reference type, a table type, or a structured type with deep components. As of Release 6.10, the VALUE addition can also be used for deep data types; however, with the limitation that a start value val can only be specified for the ABAP type string, and otherwise only IS INITIAL.

I hope this solcves ur problem

Note: rewrad if useful

Read only

Former Member
0 Likes
1,409

Hi,

Type is Abstract description of an object. Either a data type for a data object or an object type for an object inABAP Objects. The corresponding generic data type is any. Wont occupy any memory at the time declaration.

But Like refers to the existing data object. Occupy memory according to the referred data object.

Regards,

U. Uma

Read only

0 Likes
1,409

Hi Uma,

Thanks for Ur reply.

Is memory of a variable declared with LIKE changes according to the change made to the refering one?

Thanks and Regards

Mahesh.

Read only

0 Likes
1,409

Hi mahesh,

1.Is memory of a variable declared with LIKE changes according to the change made to the refering one

Absolutely NO.

2. LIKE only specifies information for data type, length etc.

3. The memory of that variable is its own memory, and is independent

of other variables/memory.

regards,

amit m.

Read only

0 Likes
1,409

Thnaks Amit,

Read only

Former Member
0 Likes
1,409

Thanks all ...

Thanks for your valuble suggestion..

Thanks and Regards

Mahesh.