<?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: Type casting in OOPS ABAP in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/type-casting-in-oops-abap/m-p/3898936#M935686</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;A cast is performed using the CASTINGaddition of the ASSIGN statement. The CASTINGaddition allows you to assign a data object to a field symbol where the type of the data object is incompatible with that of the field symbol. There are two types of casting: casting with an implicit type declaration and casting with an explicit type declaration.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Refer this thread below.&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="5417941"&gt;&lt;/A&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;Rgds,&lt;/P&gt;&lt;P&gt;Anita&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 02 Jun 2008 06:10:23 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-06-02T06:10:23Z</dc:date>
    <item>
      <title>Type casting in OOPS ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/type-casting-in-oops-abap/m-p/3898935#M935685</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;             Could any one explain me about Type casting used in oops abap and in what circumstances it is &lt;/P&gt;&lt;P&gt;used with an example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Pradeep P.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Jun 2008 04:32:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/type-casting-in-oops-abap/m-p/3898935#M935685</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-02T04:32:57Z</dc:date>
    </item>
    <item>
      <title>Re: Type casting in OOPS ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/type-casting-in-oops-abap/m-p/3898936#M935686</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;A cast is performed using the CASTINGaddition of the ASSIGN statement. The CASTINGaddition allows you to assign a data object to a field symbol where the type of the data object is incompatible with that of the field symbol. There are two types of casting: casting with an implicit type declaration and casting with an explicit type declaration.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Refer this thread below.&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="5417941"&gt;&lt;/A&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;Rgds,&lt;/P&gt;&lt;P&gt;Anita&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Jun 2008 06:10:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/type-casting-in-oops-abap/m-p/3898936#M935686</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-02T06:10:23Z</dc:date>
    </item>
    <item>
      <title>Re: Type casting in OOPS ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/type-casting-in-oops-abap/m-p/3898937#M935687</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;yea man 2 sort of casting&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. narrow&lt;/P&gt;&lt;P&gt;2.widen casting..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;narrow allows to use redefine method and inherited component of super class..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;example is BADI which using this casting because it can make multiple implementation in interface for class....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;second is widen which let use redefine method inherited as well new component of subclass.. soo call upcast casting also....&lt;/P&gt;&lt;P&gt; basically this used by interface to dynamically checking relation..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Jun 2008 06:39:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/type-casting-in-oops-abap/m-p/3898937#M935687</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-02T06:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: Type casting in OOPS ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/type-casting-in-oops-abap/m-p/3898938#M935688</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Go to ABAPDOCU tcode and see example programs in abap objects section, you will find separate programs for upcasting and downcasting .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Up-Cast (Widening Cast)&lt;/P&gt;&lt;P&gt;Variables of the type reference to superclass can also refer to subclass instances at runtime.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you assign a subclass reference to a superclass reference, this ensures that&lt;/P&gt;&lt;P&gt;all components that can be accessed syntactically after the cast assignment are&lt;/P&gt;&lt;P&gt;actually available in the instance. The subclass always contains at least the same&lt;/P&gt;&lt;P&gt;components as the superclass. After all, the name and the signature of redefined&lt;/P&gt;&lt;P&gt;methods are identical.&lt;/P&gt;&lt;P&gt;The user can therefore address the subclass instance in the same way as the&lt;/P&gt;&lt;P&gt;superclass instance. However, he/she is restricted to using only the inherited&lt;/P&gt;&lt;P&gt;components.&lt;/P&gt;&lt;P&gt;In this example, after the assignment, the methods GET_MAKE, GET_COUNT,&lt;/P&gt;&lt;P&gt;DISPLAY_ATTRIBUTES, SET_ATTRIBUTES and ESTIMATE_FUEL of the&lt;/P&gt;&lt;P&gt;instance LCL_TRUCK can only be accessed using the reference R_VEHICLE.&lt;/P&gt;&lt;P&gt;If there are any restrictions regarding visibility, they are left unchanged. It is not&lt;/P&gt;&lt;P&gt;possible to access the specific components from the class LCL_TRUCK of the&lt;/P&gt;&lt;P&gt;instance (GET_CARGO in the above example) using the reference R_VEHICLE.&lt;/P&gt;&lt;P&gt;The view is thus usually narrowed (or at least unchanged). That is why we&lt;/P&gt;&lt;P&gt;describe this type of assignment of reference variables as up-cast. There is a&lt;/P&gt;&lt;P&gt;switch from a view of several components to a view of a few components. As&lt;/P&gt;&lt;P&gt;the target variable can accept more dynamic types in comparison to the source&lt;/P&gt;&lt;P&gt;variable, this assignment is also called Widening Cast&lt;/P&gt;&lt;P&gt;Static and Dynamic Types of References&lt;/P&gt;&lt;P&gt;A reference variable always has two types at runtime: static and dynamic.&lt;/P&gt;&lt;P&gt;In the example, LCL_VEHICLE is the static type of the variable R_VEHICLE.&lt;/P&gt;&lt;P&gt;Depending on the cast assignment, the dynamic type is either LCL_BUS or&lt;/P&gt;&lt;P&gt;LCL_TRUCK. In the ABAP Debugger, the dynamic type is specified in the form&lt;/P&gt;&lt;P&gt;of the following object display.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Down-cast (Narrowing Cast)&lt;/P&gt;&lt;P&gt;Variables of the type &amp;#147;reference to superclass&amp;#148; 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 &amp;#147;reference to subclass&amp;#148;.&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;Reward if helpfull,&lt;/P&gt;&lt;P&gt; Naresh.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Jun 2008 07:33:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/type-casting-in-oops-abap/m-p/3898938#M935688</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-02T07:33:55Z</dc:date>
    </item>
    <item>
      <title>Re: Type casting in OOPS ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/type-casting-in-oops-abap/m-p/3898939#M935689</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Narrow Casting :&lt;/STRONG&gt; It’s a
process of assigning sub class object to the super class reference it called as
Narrow cast.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Wide Casting : &lt;/STRONG&gt;It’s a
process of assigning super class object to the sub class reference it called as Wide Casting.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2020 09:35:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/type-casting-in-oops-abap/m-p/3898939#M935689</guid>
      <dc:creator>prabhu_04</dc:creator>
      <dc:date>2020-09-18T09:35:57Z</dc:date>
    </item>
  </channel>
</rss>

