Skip to Content
author's profile photo
Former Member

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

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

Many thanks!

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

4 Answers

  • Best Answer
    Posted on Aug 21, 2007 at 01:51 PM

    Hi,

    Check this Link

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      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.

  • author's profile photo
    Former Member
    Posted on Aug 21, 2007 at 01:52 PM

    hi

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

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

    Add comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 21, 2007 at 01:52 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Aug 21, 2007 at 01:52 PM

    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

    Add comment
    10|10000 characters needed characters exceeded