<?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 Regarding Narrow casting in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-narrow-casting/m-p/4511371#M1066930</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;Here i am giving one program about narrow casting in which i am not able to access the method called 'fasting', but here i am able to access dynamically.&lt;/P&gt;&lt;P&gt;So, while doing narrow casting may i know that only dynamically we can able to access that method?&lt;/P&gt;&lt;P&gt;and may i know the clear picture of wide castening &amp;amp; narrow castening with example.&lt;/P&gt;&lt;P&gt;Please help it out.&lt;/P&gt;&lt;P&gt;REPORT  Z15704_NARROWING.&lt;/P&gt;&lt;P&gt;CLASS lcl_animal DEFINITION.&lt;/P&gt;&lt;P&gt;   PUBLIC SECTION.&lt;/P&gt;&lt;P&gt;     METHODS: hungry.&lt;/P&gt;&lt;P&gt;     ENDCLASS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;     CLASS lcl_lion DEFINITION INHERITING FROM lcl_animal.&lt;/P&gt;&lt;P&gt;        PUBLIC SECTION.&lt;/P&gt;&lt;P&gt;         METHODS: hungry REDEFINITION,&lt;/P&gt;&lt;P&gt;                 fasting.&lt;/P&gt;&lt;P&gt;         ENDCLASS.&lt;/P&gt;&lt;P&gt;         CLASS lcl_animal IMPLEMENTATION.&lt;/P&gt;&lt;P&gt;           METHOD hungry.&lt;/P&gt;&lt;P&gt;               WRITE: / 'An animal is hungry'.&lt;/P&gt;&lt;P&gt;                ENDMETHOD.&lt;/P&gt;&lt;P&gt;                endclass.&lt;/P&gt;&lt;P&gt;                  "hungryENDCLASS.&lt;/P&gt;&lt;P&gt;CLASS lcl_lion IMPLEMENTATION.&lt;/P&gt;&lt;P&gt;  METHOD hungry .&lt;/P&gt;&lt;P&gt;     WRITE: / 'A Lion (King of Jungle) is hungry.'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      ENDMETHOD.                    "hungry  METHOD fasting.&lt;/P&gt;&lt;P&gt;      METHOD fasting.&lt;/P&gt;&lt;P&gt;       WRITE: / 'Stop running. Lion is on Fasting today.'.&lt;/P&gt;&lt;P&gt;       ENDMETHOD.&lt;/P&gt;&lt;P&gt;       ENDCLASS.&lt;/P&gt;&lt;P&gt;       START-OF-SELECTION.&lt;/P&gt;&lt;P&gt;        DATA: lo_animal TYPE REF TO lcl_animal,&lt;/P&gt;&lt;P&gt;                  lo_lion   TYPE REF TO lcl_lion.&lt;/P&gt;&lt;P&gt;       " ** ANIMAL object without NARROW casting&lt;/P&gt;&lt;P&gt;        WRITE: / 'Animal - without NARROW casting'.&lt;/P&gt;&lt;P&gt;         CREATE OBJECT lo_animal.&lt;/P&gt;&lt;P&gt;           CALL METHOD lo_animal-&amp;gt;hungry( ).&lt;/P&gt;&lt;P&gt;          CLEAR lo_animal.&lt;/P&gt;&lt;P&gt;          "** ANIMAL object with NARROW CASTING  SKIP 2.&lt;/P&gt;&lt;P&gt;           WRITE: / 'Animal -  NARROW casting from LION'.&lt;/P&gt;&lt;P&gt;           CREATE OBJECT lo_lion.&lt;/P&gt;&lt;P&gt;            lo_animal = lo_lion.&lt;/P&gt;&lt;P&gt;            CALL METHOD lo_animal-&amp;gt;hungry( ).&lt;/P&gt;&lt;P&gt;            CALL METHOD lo_animal-&amp;gt;fasting( ).&lt;/P&gt;&lt;P&gt;when i call  this method dynamically CALL METHOD lo_animal-&amp;gt;('fasting'). i am able to access. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Radhika&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 26 Sep 2008 12:36:41 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-09-26T12:36:41Z</dc:date>
    <item>
      <title>Regarding Narrow casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-narrow-casting/m-p/4511371#M1066930</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;Here i am giving one program about narrow casting in which i am not able to access the method called 'fasting', but here i am able to access dynamically.&lt;/P&gt;&lt;P&gt;So, while doing narrow casting may i know that only dynamically we can able to access that method?&lt;/P&gt;&lt;P&gt;and may i know the clear picture of wide castening &amp;amp; narrow castening with example.&lt;/P&gt;&lt;P&gt;Please help it out.&lt;/P&gt;&lt;P&gt;REPORT  Z15704_NARROWING.&lt;/P&gt;&lt;P&gt;CLASS lcl_animal DEFINITION.&lt;/P&gt;&lt;P&gt;   PUBLIC SECTION.&lt;/P&gt;&lt;P&gt;     METHODS: hungry.&lt;/P&gt;&lt;P&gt;     ENDCLASS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;     CLASS lcl_lion DEFINITION INHERITING FROM lcl_animal.&lt;/P&gt;&lt;P&gt;        PUBLIC SECTION.&lt;/P&gt;&lt;P&gt;         METHODS: hungry REDEFINITION,&lt;/P&gt;&lt;P&gt;                 fasting.&lt;/P&gt;&lt;P&gt;         ENDCLASS.&lt;/P&gt;&lt;P&gt;         CLASS lcl_animal IMPLEMENTATION.&lt;/P&gt;&lt;P&gt;           METHOD hungry.&lt;/P&gt;&lt;P&gt;               WRITE: / 'An animal is hungry'.&lt;/P&gt;&lt;P&gt;                ENDMETHOD.&lt;/P&gt;&lt;P&gt;                endclass.&lt;/P&gt;&lt;P&gt;                  "hungryENDCLASS.&lt;/P&gt;&lt;P&gt;CLASS lcl_lion IMPLEMENTATION.&lt;/P&gt;&lt;P&gt;  METHOD hungry .&lt;/P&gt;&lt;P&gt;     WRITE: / 'A Lion (King of Jungle) is hungry.'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      ENDMETHOD.                    "hungry  METHOD fasting.&lt;/P&gt;&lt;P&gt;      METHOD fasting.&lt;/P&gt;&lt;P&gt;       WRITE: / 'Stop running. Lion is on Fasting today.'.&lt;/P&gt;&lt;P&gt;       ENDMETHOD.&lt;/P&gt;&lt;P&gt;       ENDCLASS.&lt;/P&gt;&lt;P&gt;       START-OF-SELECTION.&lt;/P&gt;&lt;P&gt;        DATA: lo_animal TYPE REF TO lcl_animal,&lt;/P&gt;&lt;P&gt;                  lo_lion   TYPE REF TO lcl_lion.&lt;/P&gt;&lt;P&gt;       " ** ANIMAL object without NARROW casting&lt;/P&gt;&lt;P&gt;        WRITE: / 'Animal - without NARROW casting'.&lt;/P&gt;&lt;P&gt;         CREATE OBJECT lo_animal.&lt;/P&gt;&lt;P&gt;           CALL METHOD lo_animal-&amp;gt;hungry( ).&lt;/P&gt;&lt;P&gt;          CLEAR lo_animal.&lt;/P&gt;&lt;P&gt;          "** ANIMAL object with NARROW CASTING  SKIP 2.&lt;/P&gt;&lt;P&gt;           WRITE: / 'Animal -  NARROW casting from LION'.&lt;/P&gt;&lt;P&gt;           CREATE OBJECT lo_lion.&lt;/P&gt;&lt;P&gt;            lo_animal = lo_lion.&lt;/P&gt;&lt;P&gt;            CALL METHOD lo_animal-&amp;gt;hungry( ).&lt;/P&gt;&lt;P&gt;            CALL METHOD lo_animal-&amp;gt;fasting( ).&lt;/P&gt;&lt;P&gt;when i call  this method dynamically CALL METHOD lo_animal-&amp;gt;('fasting'). i am able to access. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Radhika&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Sep 2008 12:36:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-narrow-casting/m-p/4511371#M1066930</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-09-26T12:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: Regarding Narrow casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-narrow-casting/m-p/4511372#M1066931</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;In Widening cast we assign a refernce variable or runtme object of a superclass to that of subclass.&lt;/P&gt;&lt;P&gt;But before doing this, we do narrow casting.&lt;/P&gt;&lt;P&gt;In narrow casting you assign the reference variable of subclass to that of superclass.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now during widening cast there might be a possibility that&lt;/P&gt;&lt;P&gt;at runtime your superclass variable has the reference of any other its subclasses. But at the same time you are assigning a reference variable to its particular subclass. So there can be a assignment which is incompatible.&lt;/P&gt;&lt;P&gt;thats why&lt;/P&gt;&lt;P&gt;cast error occurs only in&lt;/P&gt;&lt;P&gt;Widening cast.&lt;/P&gt;&lt;P&gt;which is handled by&lt;/P&gt;&lt;P&gt;CX_SY_MOVE_CAST_ERROR&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check this link&lt;/P&gt;&lt;P&gt;I've posted one sample program in link, run this program in debugging mode&lt;/P&gt;&lt;P&gt;&lt;A class="jive_macro jive_macro_message" href="https://community.sap.com/" __jive_macro_name="message" modifiedtitle="true" __default_attr="5943095"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Abhijeet&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Sep 2008 12:59:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-narrow-casting/m-p/4511372#M1066931</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-09-26T12:59:01Z</dc:date>
    </item>
    <item>
      <title>Re: Regarding Narrow casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-narrow-casting/m-p/4511373#M1066932</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In Narrow casting, we create a object reference to the Subclass (LO_LION) first and than we assign that object reference to the reference of the Superclass (LO_ANIMAL). Here we have moved from more specific object to less specific object. &lt;/P&gt;&lt;P&gt;Refer: &lt;A href="http://help-abap.blogspot.com/2008/09/abap-objects-narrowing-cast-upcasting.html" target="test_blank"&gt;http://help-abap.blogspot.com/2008/09/abap-objects-narrowing-cast-upcasting.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In widening cast, we create a object referece to the superclass (LO_ANIMAL)  first and than we assign the object reference to the Subclass (LO_LION). Here we move from General object to Specific object. As the principal of the inheritance, every Subobject (LO_LION) will have more attributes/properties than the General object (LO_ANIMAL). So, it would not be possilbe to just create LO_ANIMAL and move to LO_LION. So, when we do the Widening cast, we need to first use the narrow casting somewhere in the program to assign proper proerties of subobject (LO_LION) to Superobject (LO_ANIMAL). Than you will successfully move that reference back to Superobject (LO_ANIMAL) to different subobject (LO_LION2).&lt;/P&gt;&lt;P&gt;Refer: &lt;A href="http://help-abap.blogspot.com/2008/09/abap-objects-widening-cast-down-casting.html" target="test_blank"&gt;http://help-abap.blogspot.com/2008/09/abap-objects-widening-cast-down-casting.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Naimesh Patel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Sep 2008 13:24:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-narrow-casting/m-p/4511373#M1066932</guid>
      <dc:creator>naimesh_patel</dc:creator>
      <dc:date>2008-09-26T13:24:17Z</dc:date>
    </item>
  </channel>
</rss>

