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

Former Member
0 Likes
868

Kindly let me know when I have to use LIKE and when I have to use TYPE Exactly.

What is the difference b/w both..

Akshihta.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
834

TYPE should refer the data types

LIKE should refer the existing objects,

EG:

field like kna1-kunnr.

filed type c or i any ..

Rewards points if help full

Regards

Suresh.s

Message was edited by:

suresh dameruppula

Message was edited by:

suresh dameruppula

Kindly let me know when I have to use LIKE and when I have to use TYPE Exactly.

What is the difference b/w both..

Akshihta.

7 REPLIES 7
Read only

Former Member
0 Likes
834

Hi,

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]

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

Thanks,

Reward If Helpful.

Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
834

Hi,

If you want to create data similar to already existing data use LIKE

if you want to create data which is of data type (Standard ABAP or any DDIC data element or structure or table type use TYPE).

Regards,

Sesh

Read only

Former Member
0 Likes
834

Hi,

check out this link..

Reward if useful.

Regards,

Pranathi.

Read only

Former Member
0 Likes
835

TYPE should refer the data types

LIKE should refer the existing objects,

EG:

field like kna1-kunnr.

filed type c or i any ..

Rewards points if help full

Regards

Suresh.s

Message was edited by:

suresh dameruppula

Message was edited by:

suresh dameruppula

Read only

Former Member
0 Likes
834

Hi akshitha,

Data: varname[(len)] type typedef [value val].

Data postcode(4) type n value ‘4001’.

Data counter type i value 1.

Data price type p decimals 2.

Data: varname like objname [value val].

Where objname is a previously declared item (or database object)

The datatype of an identifier can be specified using

->Type specific type

->Like previously defined identifier/dictionary object

TYPES: BEGIN OF X_TYPE1,

COUNTER TYPE I ,

NAME1(25) ,

SALES_DOC LIKE VBAK-VBELN ,

END OF X_TYPE1.

DATA: WS_VAR1 TYPE X_TYPE1.

DATA: WS_VAR2 LIKE WS_VAR1

rewards if useful

regards

rami

Read only

Former Member
0 Likes
834

type - to refer data types

like - to refer exsting object ( we call data object )

Simple Example :

data a type i. " It will not take any memory ( always use type when you use in the program )

data b like a . " it will take memory ( it is like data object - do not refer if possible)

Read only

Former Member
0 Likes
834

hi,

<b>TYPE <type></b>

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.

<b>ABAP Statements with TYPE References</b>

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

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 field symbol

FIELD-SYMBOLS <fs> TYPE <type>.

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

<b>LIKE <obj>.</b>

ABAP Statements with LIKE References

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.

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

METHODS <meth> ... IMPORTING|EXPORTING|CHANGING <p> LIKE <obj> ...

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 field symbol

FIELD-SYMBOLS <fs> LIKE <obj>.

The technical attributes of the field symbol <FS> are inherited from those of the declared data object <obj>. You can then only assign data objects that have these attributes.

<b>You should also avoid using the LIKE addition in other ABAP programs except to refer to data objects</b>

regards,

Ashokreddy.