Skip to Content
avatar image
Former Member

Difference between Declaring variables

Consider three cases :

1.g_table1 like sscrfields,

2.g_table2 type sscrfields,

3.g_table3 type ref to sscrfields.

What is the difference between <b>like</b> , <b>type</b> and <b>type ref</b> statements ?

Illustrate with examples.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

4 Answers

  • Best Answer
    Aug 25, 2006 at 03:16 PM

    Hi,

    Check this SAP help :

    <b>... TYPE REF TO type</b>

    Defining a typed data reference variable. Types you can use include elementary types, types defined using TYPES, or types created in the ABAP Dictionary. You can dereference completely typed data reference variables using the dereferencing operator ->* at any operand position.

    Example

    types:

    LNTYP type I.

    data:

    CNT type ref to I,

    LINE type ref to LNTYP,

    FLIGHT type ref to SFLIGHT.

    create data CNT.

    create data LINE.

    create data FLIGHT.

    CNT->* = 20.

    LINE->* = 110.

    FLIGHT->FLDATE = SY-DATUM.

    <b>... TYPE type</b>

    Effect

    The field f is created with type type. For the type, you can specify either one of the predefined types listed below, a type defined using the TYPES statement, or a type created in the ABAP Dictionary.

    The standard length ( SL ) of a field depends on its type.

    Type Explanation SL Initial value

    C Text (Character) 1 space

    N Numeric text 1 '00...0'

    D Date (YYYYMMDD) 8 '00000000'

    T Time (HHMMSS) 6 '000000'

    X Hexadecimal (HeX code) 1 X'00'

    I Integer 4 0

    P Packed number 8 0

    F Floating point number 8 0

    STRING Character sequence (string) variable-length empty string

    XSTRING Byte sequence (X string)

    variable-length empty hexadecimal string

    Example

    DATA NUMBER TYPE I.

    DATA WA_SPFLI TYPE SPFLI.

    The field NUMBER is created with type I. You can now use it in the program. In particular, you can assign numeric values to the field and use it in calculations ( ABAP number types).

    The field WA_SPFLI is created using the type of the database table SPFLI from the ABAP Dictionary. This field is structured and can be used especially for working with data from database table SPFLI.

    <b>... LIKE f1</b>

    The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas.

    See Cannot Use LIKE References to Dictionary Types.

    Effect

    Field f is created with the same field attribtues as the data object f1, which has already been declared. Any data object (field, parameter, structure...) is allowed as long as its type has been fully specified.

    f1 can be any ABAP Dictionary reference.

    Example

    DATA TABLE_INDEX LIKE SY-TABIX.

    The field TABLE_INDEX now has the same attributes as SY-TABIX (index field for internal tables).

    Note

    You should use this addition whenever you can. If the type of a field to which you are referring changes, the ABAP runtime system updates all references automatically. It also stops the system from carrying out unnecessry (and maybe undesirable) type conversions.

    Regards

    Appana

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 25, 2006 at 03:12 PM

    hi,

    The main difference between TYPE and LIKE parameter when defining or declaring the object is that TYPE is used to refer existing DATA TYPE (elementary or structured or user defined) while LIKE is used to declare data objects with reference to existing DATA OBJECTS.

    Regards

    Ashok

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 25, 2006 at 03:13 PM

    Refer the following links:

    what-is-the-difference-between-type-and-like

    Regards,

    ravi

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 25, 2006 at 03:32 PM
    Add comment
    10|10000 characters needed characters exceeded