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

Former Member
0 Likes
898

Hi all,

What is the difference between

<b>kunnr type kna1-kunnar</b> and

<b>kunnr like kna1-kunnr</b>.

Thanks in advance.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
766

Hi

If we want to declare any variable just like of other variable then

1) kunnr type kna1-kunnar :- If we use TYPE in this it means memrory for kna1-kunnar is not allocated till time only it is defined.

like type: kna1-kunnr type kna2-kunnr. then we have to use

data: kunnr type kna1-kunnar.

2) kunnr like kna1-kunnr:- It means memory is already allocated to to kna1-kunnr and we want to declare any other variable of same data type.

like data: kna1-kunnr type c.

data: kunnr like kna1-kunnr.

in simple words TYPE defines only type and memory is not allocated while DATA defines type and also allocates memory.

Aditya

7 REPLIES 7
Read only

Former Member
0 Likes
766

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,

Padmam.

Read only

Former Member
0 Likes
767

Hi

If we want to declare any variable just like of other variable then

1) kunnr type kna1-kunnar :- If we use TYPE in this it means memrory for kna1-kunnar is not allocated till time only it is defined.

like type: kna1-kunnr type kna2-kunnr. then we have to use

data: kunnr type kna1-kunnar.

2) kunnr like kna1-kunnr:- It means memory is already allocated to to kna1-kunnr and we want to declare any other variable of same data type.

like data: kna1-kunnr type c.

data: kunnr like kna1-kunnr.

in simple words TYPE defines only type and memory is not allocated while DATA defines type and also allocates memory.

Aditya

Read only

Former Member
0 Likes
766

hi ranjith,

in ur case there is no difference between type and like. but in general type and like keywords used in different scenarios as

type: to refer to existing data type [i, c, f, d, t, ..........]

ex: data: int type i

to declare the objects when types keyword is used for user defined structures.

ex: types: begin of itab,

matnr like mara-matnr,

int ytpe i,

end of itab.

data: itab1 type itab. // we should not use like keyword as like keyword is only used for existing data objects [ standard database table, structures,.........]

ex: data: itab like standard table of mara with header line.

if helpful reward some points.

with regards,

Suresh Aluri.

Read only

Former Member
0 Likes
766

hi ranjith,

in ur case there is no difference between type and like. but in general type and like keywords used in different scenarios as

type: to refer to existing data type [i, c, f, d, t, ..........]

ex: data: int type i

to declare the objects when types keyword is used for user defined structures.

ex: types: begin of itab,

matnr like mara-matnr,

int ytpe i,

end of itab.

data: itab1 type itab. // we should not use like keyword as like keyword is only used for existing data objects [ standard database table, structures,.........]

ex: data: itab like standard table of mara with header line.

if helpful reward some points.

with regards,

Suresh Aluri.

Read only

Former Member
0 Likes
766

Hi

this is the syntax and information about the like and type

reward if usefull

DATA dobj { {TYPE [LINE OF] type}

| {LIKE [LINE OF] dobj} }

[VALUE val|{IS INITIAL}]

[READ-ONLY].

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.

Read only

Former Member
0 Likes
766

Hi Reddy

type is used for data types , like char,int

like is used for data dictionary fields,

but in u r case no diff

reward points to all helpful answers

kiran.M

Read only

Former Member
0 Likes
766

Hello,

Type : It refers to existing data type (Standard Data Types ( i,c,...)).

Like : It refers to data objects

Eg :

Data : name(10) type c. "Reffers a data type c.

Data : first_name like name,

last_name like name. "Reffers data object name

Regards,

LIJO JOHN.