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: 

like and type

Former Member
0 Kudos

hi

friends can anybody tell me the exact difference between like and type keyword.

with example.

thanks

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi,

LIKE is used to refer the data object where as TYPE is used to refer the data type.

6 REPLIES 6

Former Member
0 Kudos

hi,

LIKE is used to refer the data object where as TYPE is used to refer the data type.

Former Member
0 Kudos

Hi Savita,

If you are declaring a structure while coding e.g. <i>DATA ls_flight type sflight</i> then you can declare a field using the <b>LIKE</b> statement. E.g. <i>DATA lv_carrid LIKE ls_flight-carrid</i>.

However, for direct declaration you use the <b>TYPE</b> statement. Eg. <i>DATA lv_carrid TYPE sflight-carrid</i>. Also, TYPE is used when you declare a type in your program using a TYPES statement.

Hope this helps.

Regards,

Neha

Former Member
0 Kudos

Hi,

Diff bn TYPE N LIKE.

If you are refering to a Data object use LIKE

And if you are refering to a Data type use TYPE

You can create a variable that inherits exactly the same technical attributes as an existing data type or data object as follows:

DATA <f> [TYPE <type>|LIKE <obj>]...

If you use the TYPE addition, <type> is any data type with fully-specified technical attributes. This can be a:

Non-generic predefined ABAP type (D, F, I, T, STRING, XSTRING)

Any existing local data type in the program.

Any ABAP Dictionary data type

If you use the LIKE addition, <obj> is a data object that has already been declared. This can also be a predefined data object. The variable <f> adopts the same technical attributes as the data object <obj>. You can also use LIKE to refer to a line of an internal table that has already been declared as a data object:

DATA <f> LIKE LINE OF <itab>.

To ensure compatibility with previous releases, <obj> can also be a database table, a view, a structure, or a component of a structure from the ABAP Dictionary.

The data types to which you refer can be elementary types, reference types, or complex types (structures or tables). For elementary field types, the variables are a single field in memory. When you declare a data type with fixed length (D, F, I, T) the system fixes the amount of memory that will be assigned. When you declare an object with a variable length (STRING, XSRTING), the system only assigns enough memory to administer the object. The length of the data object is managed dynamically at runtime. For structures, the variables are a sequence of variables, which may themselves also be included in further complex structures. The individual components take their name <ci> from the type <type> or object <obj>, and can be addressed using <f>-<c i> For tables, the memory contains administration entries that can be filled dynamically at runtime.

Go through the link.

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

For TYPE

http://help.sap.com/saphelp_47x200/helpdata/en/d3/2e974d35c511d1829f0000e829fbfe/frameset.htm

For LIKE

http://help.sap.com/saphelp_47x200/helpdata/en/d3/2e974d35c511d1829f0000e829fbfe/frameset.htm

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

LIKE means the datatype of the variable is similar to the referenced variable.

TYPE means it is a predefined data type.

Regards,

Priyanka.

Former Member
0 Kudos

Hi,

The only additional advantage with types is that you can define your own types(including complex ones) in the data dictionary and reuse them across various programs.

<b>Please read previous posting

Regards,

ABY

Former Member
0 Kudos

Hi,

The LIKE Addition:

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

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

reward if it helps..

Regards,

Omkar.

Former Member
0 Kudos

thanks for all i got the answer