Application Development 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: 

Difference b/w like and type

Former Member
0 Kudos

Difference b/w like and type

1 ACCEPTED SOLUTION

Former Member
0 Kudos

HI

<b>TYPE</b>

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.

<b>LIKE</b>

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

<b>Reward if usefull</b>

6 REPLIES 6

former_member404244
Active Contributor
0 Kudos

abdulazeez12
Active Contributor
0 Kudos

hi,

Like Addition

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

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.

TYPE Addition

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.

Referring to Known Data Types

You can use the addition

TYPE <type>

to refer to any data type <type> that is already known at this point in the program. It can be used in any of the statements listed below. The expression <obj> is either the name of the data object or the expression

LINE OF <table-type>

In this case, the TYPE addition describes the line type of a table type <table-type> that is visible at that point in the program.

<b>Reward if useful</b>

Regards

Shakir

Former Member
0 Kudos

we use like when we refer to "data object" here memory is allocated.

while when we use type we refer to "data type" no memory allocation takes place.

regards,

Quavi

pl reward points if helpful

Former Member
0 Kudos

HI

<b>TYPE</b>

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.

<b>LIKE</b>

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

<b>Reward if usefull</b>

harimanjesh_an
Active Participant
0 Kudos

hi mahesh,

i have just told these in simple words........... for further information check at SDN...

<u><b>type Versus like</b></u>

Always use the like addition to define a parameter. When you use it, the parameter acquires the following attributes from the Data Dictionary:

F1 help is acquired from the Documentation button in the data element.

F4 help is acquired if your parameter is like one that has a check table.

A field label is acquired from the data element.

In addition to the advantages provided by the above,

1) A field label obtained from the Data Dictionary is guaranteed to be consistent with the field label presented by other programs for the same field (provided they also obtain them from the DDIC). This eliminates the confusion of having two fields that are labeled differently refer to the same data.

2)Modifications to the data type or length in the DDIC are automatically reflected by your program.

In view of all of these advantages, you should always use the like addition to define a parameter. This applies even to check boxes and radio buttons. If necessary, you should create a structure in the DDIC so that you can use like and at a minimum, provide F1 help. Note that F1 help is available even for radio buttons and check boxes.

reward me if useful.......

regards.....

Former Member
0 Kudos

Very Simple...

Type ---> refering to a data type

Like ---> refering to a variable...

eg.. data : name(10) type c,

long_name like name.