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: 

Newbie Question: What's the difference bewteen LIKE and TYPE?

Former Member
0 Kudos

I'm confused about the difference between LIKE and TYPE. Can someone give me the layman's definition?

Many thanks!

1 ACCEPTED SOLUTION

former_member194669
Active Contributor
0 Kudos

Hi,

Check this Link

5 REPLIES 5

former_member194669
Active Contributor
0 Kudos

Hi,

Check this Link

0 Kudos

Hope it's ok to follow up with a question on a closed topic but I'm confused as to why you just wouldn't use TYPE again instead of using a LIKE with a data object. For instance, instead of


DATA counts TYPE i.

TYPES: company TYPE spfli-carrid,
             no_flights LIKE counts.

why not just write


DATA counts TYPE i.

TYPES:  company TYPE spfli-carrid,
              no_flights TYPE i.   <--- Using TYPE instead of LIKE

Not sure what you're gaining by using LIKE instead of the TYPE of the referenced data object directly.

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Please see the section Referring to Known Data Types or Data Objects

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

Regards,

Rich Heilman

Former Member
0 Kudos

hi

if we declare as type no memory is allocated for that variable

where as like refers to dataobjects...memory is alocated for them

Former Member
0 Kudos

TYPES

Syntax Forms

Use Predefined Types

1. TYPES { {dtype[(len)] TYPE abap_type [DECIMALS dec]}

| {dtype TYPE abap_type [LENGTH len] [DECIMALS dec]} }.

Refer to Existing Types

2. TYPES dtype { {TYPE [LINE OF] type}

| {LIKE [LINE OF] dobj} }.

Reference Types

3. TYPES dtype { {TYPE REF TO type}

| {LIKE REF TO dobj} }.

Structured Types

4. TYPES BEGIN OF struc_type.

...

{TYPES dtype ...} | {INCLUDE {TYPE|STRUCTURE} ...}.

...

TYPES END OF struc_type.

Table Types

5. TYPES dtype { {TYPE tabkind OF [REF TO] type}

| {LIKE tabkind OF dobj} }

[WITH key] [INITIAL SIZE n].

Ranges Table Types

6. TYPES dtype {TYPE RANGE OF type}|{LIKE RANGE OF dobj}

[INITIAL SIZE n].

Effect

The TYPES statement defines either an independent data type dtype or a structured data type struc_type. The naming conventions apply to the names dtype and struc_type. The defined data type can be viewed within the current context from this position.

Any data type dtype is either defined with the addition TYPE and a type, or with the addition LIKE and a data object. The syntax allows you to define elementary data types, reference types, structured types, and table types.

For the definition of a structured type struc_type, any type definitions of two TYPES statements are included with the additions BEGIN OF and END OF; a structured data type struc_type is defined here, which contains the included data types as components struc_type-dtype. The structure definitions can be nested.

<b>Note

Outside of ABAP Objects, you can use the addition LIKE to refer to the properties of data objects as well as the flat structures, database tables, or Views of the ABAP Dictionary. </b>

Regards

Preeti