<?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: Casting in ABAP Objects in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting-in-abap-objects/m-p/4040325#M965693</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hiii,&lt;/P&gt;&lt;P&gt;shayam if you are not doing the NARROW CASTING before you are performing the WIDE CASTING ,then the cast errors are bound to come...&lt;/P&gt;&lt;P&gt;if you need a detailed description...let me know..&lt;/P&gt;&lt;P&gt;reward if helpful..&lt;/P&gt;&lt;P&gt;thanks..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 25 Jun 2008 07:20:01 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-06-25T07:20:01Z</dc:date>
    <item>
      <title>Casting in ABAP Objects</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting-in-abap-objects/m-p/4040320#M965688</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why the cast error generates only in Widening cast?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Jun 2008 13:44:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/casting-in-abap-objects/m-p/4040320#M965688</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-24T13:44:43Z</dc:date>
    </item>
    <item>
      <title>Re: Casting in ABAP Objects</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting-in-abap-objects/m-p/4040321#M965689</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;See this &lt;SPAN __jive_macro_name="thread" id="313275"&gt;&lt;/SPAN&gt; and &lt;SPAN __jive_macro_name="thread" id="731414"&gt;&lt;/SPAN&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Jun 2008 14:06:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/casting-in-abap-objects/m-p/4040321#M965689</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-24T14:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: Casting in ABAP Objects</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting-in-abap-objects/m-p/4040322#M965690</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is possible tthat the static target variable is neithrer more general than nor the same as the dynamic type of the source variable...That is why with this kind of cast the runtime system checks before the assignment wheter the current content of the source variable corresponds to the type requirements of the target variable. Otherwise, an exception that can be handled is triggered and original value of the target variable remains the same.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The exception of the error class is CX_SY_MOVE_CAST_ERROR.&lt;/P&gt;&lt;P&gt;Can be handled in TRY .... CATCH.... block.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The way to prevent this runtime error would be to use runtime tyoe identification(RTTI) classes. They can be used to determine the dynamic type at runtime and to set a condition for the cast.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this would help you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Narin Nandivada.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Jun 2008 14:11:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/casting-in-abap-objects/m-p/4040322#M965690</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-24T14:11:33Z</dc:date>
    </item>
    <item>
      <title>Re: Casting in ABAP Objects</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting-in-abap-objects/m-p/4040323#M965691</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Shyam,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;WELCOME TO SDN!!!&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please check this link&lt;/P&gt;&lt;P&gt;&lt;A href="http://abapprogramming.blogspot.com/2007/10/oops-abap-8.html" target="test_blank"&gt;http://abapprogramming.blogspot.com/2007/10/oops-abap-8.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The widening cast in this case does not cause an error because the reference airplane actually points to an instance in the subclass lcl_cargo_airplane. The dynamic type is therefore u2018REF TO lcl_cargo_airplaneu2019.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here the widening cast produces the MOVE_CAST_ERROR runtime error that can be caught with u201CCATCH ... ENDCATCHu201D, because the airplane reference does not point to an instance in the subclass lcl_cargo_airplane, but to a u201Cgeneral airplane objectu201D. Its dynamic type is therefore u2018REF TO lcl_airplaneu2019 and does not correspond to the reference type cargo_airplane.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The widening cast logically represents the opposite of the narrowing cast. The widening cast cannot be checked statically, only at runtime. The Cast Operator u201C?=u201D (or the equivalent u201CMOVE ... ?TO u2026u201D) must be used to make this visible.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With this kind of cast, a check is carried out at runtime to ensure that the current content of the source variable corresponds to the type requirements of the target variables. In this case therefore, it checks that the dynamic type of the source reference airplane is compatible with the static type of the target reference cargo_airplane. If it is, the assignment is carried out. Otherwise the catchable runtime error u201CMOVE_CAST_ERRORu201D occurs, and the original value of the target variable remains the same.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Best regards,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;raam&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Jun 2008 14:13:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/casting-in-abap-objects/m-p/4040323#M965691</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-24T14:13:20Z</dc:date>
    </item>
    <item>
      <title>Re: Casting in ABAP Objects</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting-in-abap-objects/m-p/4040324#M965692</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Shyam,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think there is a confusion. I think your question is about down casting and not wide casting.&lt;/P&gt;&lt;P&gt;Can you please re-confirm.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Wider/up casting : &lt;/P&gt;&lt;P&gt;              This means a ref object used is of a parent. Now here technically speaking you can only call the methods of the parent class and not of the child class. Even if the parent object is referencing to a child object at runtime, the compiler does not allow you to call the child method.&lt;/P&gt;&lt;P&gt;So there is an error as it can be detected by the compiler and therefore does not have run-time errors.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. Narrow/down casting :&lt;/P&gt;&lt;P&gt;             This means a ref object used is of a child. Now here technically speaking you can call all the methods of the parent class as well as of the child class. So in this case, at runtime if the child object point to a prent object then it will cause an issue if a method specific to a child is called.For the compiler it is not possible to detect this at compile time, like in the above case and therefore a runtime exception is possible. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope the above explaination helps you understand this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Saurabh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jun 2008 04:46:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/casting-in-abap-objects/m-p/4040324#M965692</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-25T04:46:19Z</dc:date>
    </item>
    <item>
      <title>Re: Casting in ABAP Objects</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting-in-abap-objects/m-p/4040325#M965693</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hiii,&lt;/P&gt;&lt;P&gt;shayam if you are not doing the NARROW CASTING before you are performing the WIDE CASTING ,then the cast errors are bound to come...&lt;/P&gt;&lt;P&gt;if you need a detailed description...let me know..&lt;/P&gt;&lt;P&gt;reward if helpful..&lt;/P&gt;&lt;P&gt;thanks..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jun 2008 07:20:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/casting-in-abap-objects/m-p/4040325#M965693</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-25T07:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: Casting in ABAP Objects</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting-in-abap-objects/m-p/4040326#M965694</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hii!&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;Regards&lt;/P&gt;&lt;P&gt;Abhijeet Kulshreshtha&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Jun 2008 06:18:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/casting-in-abap-objects/m-p/4040326#M965694</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-27T06:18:33Z</dc:date>
    </item>
    <item>
      <title>Re: Casting in ABAP Objects</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting-in-abap-objects/m-p/4040327#M965695</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi shyam&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;welcome to SDN.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;please check this link.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;[http://abapprogramming.blogspot.com/2007/10/oops-abap-8.html]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hope this will help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;reward if helpful&lt;/P&gt;&lt;P&gt;Sumit Agarwal&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 28 Jun 2008 06:35:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/casting-in-abap-objects/m-p/4040327#M965695</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-28T06:35:44Z</dc:date>
    </item>
  </channel>
</rss>

