<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: doubt in casting in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/doubt-in-casting/m-p/2901450#M682348</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Lokesh,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let me explain you about this using another example than your example which would gives you a better understanding on the casting.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The use of casting is to assign the same memory location to both the classes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let us assume that there are two classes, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) Animal ( Class )&lt;/P&gt;&lt;P&gt;2) Dog     ( Class )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dog inherits all properties from the Animal, So Dog is the child class and Animal is the Super class.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If i create the instance of the Animal class and Assigns the same to the Dog, it is called as the Widening casting ( or Down Casting ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I do reverse to it... If I create the Dog object and assigns the same to the Animal, this is called as the Narrowing casting ( or Up Casting )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below example would give you a better idea on casting and it would also answers your question properly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

*----------------------------------------------------------------------*
*       CLASS C1 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS C1 DEFINITION.
  PUBLIC SECTION.
    data: var1 type ref to object.
    METHODS: METH1.
ENDCLASS.                    "C1 DEFINITION
*----------------------------------------------------------------------*
*       CLASS C1 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS C1 IMPLEMENTATION.
  METHOD METH1.
    WRITE: / 'This is a method one in class C1'.
  ENDMETHOD.                                                "METH1
ENDCLASS.                    "C1 IMPLEMENTATION
*----------------------------------------------------------------------*
*       CLASS C2 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS C2 DEFINITION inheriting from c1.
  PUBLIC SECTION.
    METHODS: METH2, meth1 redefinition.
ENDCLASS.                    "C2 DEFINITION

*----------------------------------------------------------------------*
*       CLASS C2 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS C2 IMPLEMENTATION.
  METHOD METH2.
    WRITE: / 'This is a method two'.
  ENDMETHOD.
   METHOD METH1.
    WRITE: / 'This is a method one in class C2'.
    call method super-&amp;gt;meth1.
   ENDMETHOD.
ENDCLASS.                    "C2 IMPLEMENTATION

START-OF-SELECTION.

  DATA REF1 TYPE REF TO C1.
  DATA REF2 TYPE REF TO C2.

  CREATE OBJECT REF2.
  ref1 = ref2.
  ref2 ?= ref1.

  call method ref1-&amp;gt;meth1.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Sreekanth&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;i&amp;gt; Reward if it helps you&amp;lt;/i&amp;gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 29 Oct 2007 17:55:13 GMT</pubDate>
    <dc:creator>sreekanthgo</dc:creator>
    <dc:date>2007-10-29T17:55:13Z</dc:date>
    <item>
      <title>doubt in casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/doubt-in-casting/m-p/2901448#M682346</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi sdns,&lt;/P&gt;&lt;P&gt;           i am new to OOABAP.I am being trained on this concepts.I am facing a lot of difficulty in understanding Narrowing Cast &amp;amp; Widening Cast.I have some doubts in that.&lt;/P&gt;&lt;P&gt;     i have a doubt in widening cast.I Know  that we are increasing the scope with the same object in widening cast.&lt;/P&gt;&lt;P&gt;if we have two classes airplane,cargo_airplane&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: airplane TYPE REF TO lcl_airplane,&lt;/P&gt;&lt;P&gt;cargo_airplane TYPE REF TO lcl_cargo_airplane,&lt;/P&gt;&lt;P&gt;cargo_airplane2 TYPE REF TO lcl_cargo_airplane.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CREATE OBJECT cargo_airplane.&lt;/P&gt;&lt;P&gt;airplane = cargo_airplane.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cargo_airplane2 ?= airplane.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if we have a method in airplane.we have a redefined it in cargo_airplane.&lt;/P&gt;&lt;P&gt;After this widening cast.&lt;/P&gt;&lt;P&gt;if we acccess this method from cargo_airplane2.&lt;/P&gt;&lt;P&gt;which method will it access redefined method or the method in super class.&lt;/P&gt;&lt;P&gt;please do explain me this example clearly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;with regards,&lt;/P&gt;&lt;P&gt;lokesh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Oct 2007 04:21:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/doubt-in-casting/m-p/2901448#M682346</guid>
      <dc:creator>lokesh_kamana</dc:creator>
      <dc:date>2007-10-24T04:21:33Z</dc:date>
    </item>
    <item>
      <title>Re: doubt in casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/doubt-in-casting/m-p/2901449#M682347</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Lokesh,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The redefined method will be accessed. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Bhooma&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Oct 2007 16:52:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/doubt-in-casting/m-p/2901449#M682347</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-10-29T16:52:56Z</dc:date>
    </item>
    <item>
      <title>Re: doubt in casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/doubt-in-casting/m-p/2901450#M682348</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Lokesh,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let me explain you about this using another example than your example which would gives you a better understanding on the casting.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The use of casting is to assign the same memory location to both the classes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let us assume that there are two classes, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) Animal ( Class )&lt;/P&gt;&lt;P&gt;2) Dog     ( Class )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dog inherits all properties from the Animal, So Dog is the child class and Animal is the Super class.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If i create the instance of the Animal class and Assigns the same to the Dog, it is called as the Widening casting ( or Down Casting ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I do reverse to it... If I create the Dog object and assigns the same to the Animal, this is called as the Narrowing casting ( or Up Casting )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below example would give you a better idea on casting and it would also answers your question properly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

*----------------------------------------------------------------------*
*       CLASS C1 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS C1 DEFINITION.
  PUBLIC SECTION.
    data: var1 type ref to object.
    METHODS: METH1.
ENDCLASS.                    "C1 DEFINITION
*----------------------------------------------------------------------*
*       CLASS C1 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS C1 IMPLEMENTATION.
  METHOD METH1.
    WRITE: / 'This is a method one in class C1'.
  ENDMETHOD.                                                "METH1
ENDCLASS.                    "C1 IMPLEMENTATION
*----------------------------------------------------------------------*
*       CLASS C2 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS C2 DEFINITION inheriting from c1.
  PUBLIC SECTION.
    METHODS: METH2, meth1 redefinition.
ENDCLASS.                    "C2 DEFINITION

*----------------------------------------------------------------------*
*       CLASS C2 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS C2 IMPLEMENTATION.
  METHOD METH2.
    WRITE: / 'This is a method two'.
  ENDMETHOD.
   METHOD METH1.
    WRITE: / 'This is a method one in class C2'.
    call method super-&amp;gt;meth1.
   ENDMETHOD.
ENDCLASS.                    "C2 IMPLEMENTATION

START-OF-SELECTION.

  DATA REF1 TYPE REF TO C1.
  DATA REF2 TYPE REF TO C2.

  CREATE OBJECT REF2.
  ref1 = ref2.
  ref2 ?= ref1.

  call method ref1-&amp;gt;meth1.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Sreekanth&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;i&amp;gt; Reward if it helps you&amp;lt;/i&amp;gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Oct 2007 17:55:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/doubt-in-casting/m-p/2901450#M682348</guid>
      <dc:creator>sreekanthgo</dc:creator>
      <dc:date>2007-10-29T17:55:13Z</dc:date>
    </item>
  </channel>
</rss>

