<?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: Narrow Casting in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/narrow-casting/m-p/4103145#M981211</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;Narrowing Cast &lt;/P&gt;&lt;P&gt;If the static type of the target variable is less specific or the same as the static type of the source variable, assignment is always possible. In comparison to the source variable, the target variable knows the same or fewer attributes of the dynamic type. As a result, this assignment is referred to as narrowing cast. A narrowing cast is possible in all ABAP statements in which the content of a data object is assigned to another data object. These include, for example, assignments with the normal assignment operator (=), the insertion of rows in internal tables, or the transfer from actual to formal parameters.&lt;/P&gt;&lt;P&gt;&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;Variables of the type reference to superclass can also refer to subclass instances&lt;/P&gt;&lt;P&gt;at runtime. You may now want to copy such a reference (back) to a suitable&lt;/P&gt;&lt;P&gt;variable of the type reference to subclass.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to assign a superclass reference to a subclass reference, you must&lt;/P&gt;&lt;P&gt;use the down-cast assignment operator MOVE ... ?TO ... or its short form&lt;/P&gt;&lt;P&gt;?=. Otherwise, you would get a message stating that it is not certain that all&lt;/P&gt;&lt;P&gt;components that can be accessed syntactically after the cast assignment are&lt;/P&gt;&lt;P&gt;actually available in the instance. As a rule, the subclass class contains more&lt;/P&gt;&lt;P&gt;components than the superclass.&lt;/P&gt;&lt;P&gt;After assigning this type of reference (back) to a subclass reference to the&lt;/P&gt;&lt;P&gt;implementing class, clients are no longer limited to inherited components: In the&lt;/P&gt;&lt;P&gt;example given here, all components of the LCL_TRUCK instance can be accessed&lt;/P&gt;&lt;P&gt;(again) after the assignment using the reference R_TRUCK2.&lt;/P&gt;&lt;P&gt;The view is thus usually widened (or at least unchanged). That is why we describe&lt;/P&gt;&lt;P&gt;this type of assignment of reference variables as down-cast. There is a switch&lt;/P&gt;&lt;P&gt;from a view of a few components to a view of more components. As the target&lt;/P&gt;&lt;P&gt;variable can accept less dynamic types after the assignment, this assignment is&lt;/P&gt;&lt;P&gt;also called Narrowing Cast&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward points if useful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Sekhar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 30 Jun 2008 06:06:06 GMT</pubDate>
    <dc:creator>former_member188594</dc:creator>
    <dc:date>2008-06-30T06:06:06Z</dc:date>
    <item>
      <title>Narrow Casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/narrow-casting/m-p/4103144#M981210</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anybody please tell the usuage of narrow casting.&lt;/P&gt;&lt;P&gt;preferable with simple code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anirban Bhattacharjee&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 28 Jun 2008 10:09:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/narrow-casting/m-p/4103144#M981210</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-28T10:09:03Z</dc:date>
    </item>
    <item>
      <title>Re: Narrow Casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/narrow-casting/m-p/4103145#M981211</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;Narrowing Cast &lt;/P&gt;&lt;P&gt;If the static type of the target variable is less specific or the same as the static type of the source variable, assignment is always possible. In comparison to the source variable, the target variable knows the same or fewer attributes of the dynamic type. As a result, this assignment is referred to as narrowing cast. A narrowing cast is possible in all ABAP statements in which the content of a data object is assigned to another data object. These include, for example, assignments with the normal assignment operator (=), the insertion of rows in internal tables, or the transfer from actual to formal parameters.&lt;/P&gt;&lt;P&gt;&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;Variables of the type reference to superclass can also refer to subclass instances&lt;/P&gt;&lt;P&gt;at runtime. You may now want to copy such a reference (back) to a suitable&lt;/P&gt;&lt;P&gt;variable of the type reference to subclass.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to assign a superclass reference to a subclass reference, you must&lt;/P&gt;&lt;P&gt;use the down-cast assignment operator MOVE ... ?TO ... or its short form&lt;/P&gt;&lt;P&gt;?=. Otherwise, you would get a message stating that it is not certain that all&lt;/P&gt;&lt;P&gt;components that can be accessed syntactically after the cast assignment are&lt;/P&gt;&lt;P&gt;actually available in the instance. As a rule, the subclass class contains more&lt;/P&gt;&lt;P&gt;components than the superclass.&lt;/P&gt;&lt;P&gt;After assigning this type of reference (back) to a subclass reference to the&lt;/P&gt;&lt;P&gt;implementing class, clients are no longer limited to inherited components: In the&lt;/P&gt;&lt;P&gt;example given here, all components of the LCL_TRUCK instance can be accessed&lt;/P&gt;&lt;P&gt;(again) after the assignment using the reference R_TRUCK2.&lt;/P&gt;&lt;P&gt;The view is thus usually widened (or at least unchanged). That is why we describe&lt;/P&gt;&lt;P&gt;this type of assignment of reference variables as down-cast. There is a switch&lt;/P&gt;&lt;P&gt;from a view of a few components to a view of more components. As the target&lt;/P&gt;&lt;P&gt;variable can accept less dynamic types after the assignment, this assignment is&lt;/P&gt;&lt;P&gt;also called Narrowing Cast&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward points if useful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Sekhar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jun 2008 06:06:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/narrow-casting/m-p/4103145#M981211</guid>
      <dc:creator>former_member188594</dc:creator>
      <dc:date>2008-06-30T06:06:06Z</dc:date>
    </item>
    <item>
      <title>Re: Narrow Casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/narrow-casting/m-p/4103146#M981212</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&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, technically speaking you can call all the methods of the parent class as well as of the child class due to inheritance. Typically you need narrow casting whenever you do wider casting. This is because after wider casting it is not possible to call child class specific methods.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For eg.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Class p1&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt; method x.&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Class c1 parent p1&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;method y.    (this class also has method x due to inheritance)&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA : p type ref to p1.     -&lt;/P&gt;&lt;HR originaltext="---" /&gt;&lt;P&gt;&amp;gt; here p is a ref to parent object.&lt;/P&gt;&lt;P&gt;           c type ref to c1      -&lt;/P&gt;&lt;HR originaltext="----" /&gt;&lt;P&gt;&amp;gt; here c is a ref to child object.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA : obj type ref to c1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CREATE OBJECT obj.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;p = obj.    -&lt;/P&gt;&lt;HR originaltext="---" /&gt;&lt;P&gt;&amp;gt; this is wider casting.&lt;/P&gt;&lt;P&gt;In thi case it is not possible to call method y as p is a reference to a parent object.&lt;/P&gt;&lt;P&gt; So let us say now if you want to call the method y then you can do the following.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;c ?= p.  -&lt;/P&gt;&lt;HR originaltext="----" /&gt;&lt;P&gt;&amp;gt; this is narrow casting. &lt;/P&gt;&lt;P&gt;c--&amp;gt;y.  -&lt;/P&gt;&lt;HR originaltext="----" /&gt;&lt;P&gt;&amp;gt; call to method y is possible.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this helps you. Be careful, narrow casting can lead to run time errors if the object assigned to reference does not have the right scope.&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>Mon, 30 Jun 2008 06:06:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/narrow-casting/m-p/4103146#M981212</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-30T06:06:12Z</dc:date>
    </item>
    <item>
      <title>Re: Narrow Casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/narrow-casting/m-p/4103147#M981213</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks all.&lt;/P&gt;&lt;P&gt;I hav got the concept&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jun 2008 11:15:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/narrow-casting/m-p/4103147#M981213</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-30T11:15:35Z</dc:date>
    </item>
  </channel>
</rss>

