<?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: About casting in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/about-casting/m-p/3819809#M918690</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&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="5247426"&gt;&lt;/A&gt;&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="3450970"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward points..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 20 May 2008 04:51:47 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-05-20T04:51:47Z</dc:date>
    <item>
      <title>About casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/about-casting/m-p/3819808#M918689</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Any body can u tell me the purpous of casting and tell me the difference b/w narrowing and widening&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 May 2008 04:28:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/about-casting/m-p/3819808#M918689</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-20T04:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: About casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/about-casting/m-p/3819809#M918690</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&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="5247426"&gt;&lt;/A&gt;&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="3450970"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward points..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 May 2008 04:51:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/about-casting/m-p/3819809#M918690</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-20T04:51:47Z</dc:date>
    </item>
    <item>
      <title>Re: About casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/about-casting/m-p/3819810#M918691</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Venkatesh,,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this Information will be helpful for u..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;A href="http://help.sap.com/bestpractices/BBLibrary/HTML/J58_CustConsProc_EN_KO.htm" target="test_blank"&gt;http://help.sap.com/bestpractices/BBLibrary/HTML/J58_CustConsProc_EN_KO.htm&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regard with points if you find this info helpful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Karan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 May 2008 05:22:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/about-casting/m-p/3819810#M918691</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-20T05:22:35Z</dc:date>
    </item>
    <item>
      <title>Re: About casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/about-casting/m-p/3819811#M918692</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&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;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Shiva Kumar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 May 2008 05:22:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/about-casting/m-p/3819811#M918692</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-20T05:22:46Z</dc:date>
    </item>
    <item>
      <title>Re: About casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/about-casting/m-p/3819812#M918693</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;simple language &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;with narrow casting u can use superclass redefind method and also inherited component.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;with wider casting u can access all redefine as well as all componenet of subclass and also inherited component ....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;basically known as upcast and downcast..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hope u get help give poins if u can...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 May 2008 10:18:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/about-casting/m-p/3819812#M918693</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-26T10:18:23Z</dc:date>
    </item>
    <item>
      <title>Re: About casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/about-casting/m-p/3819813#M918694</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;In Narrowing Cast the variables that are defined as "reference to super class" can also point to subclass references at program runtime. It is used to execute generic methods of the classes that exist in the same inheritance tree.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In Widening Cast the variables that are defined as "reference to subclass" can also point to superclass references at program runtime. It is used to execute specific method of a class that exist in the same inheritance tree.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward if helpful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Murthy.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 May 2008 14:12:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/about-casting/m-p/3819813#M918694</guid>
      <dc:creator>former_member787646</dc:creator>
      <dc:date>2008-05-26T14:12:07Z</dc:date>
    </item>
    <item>
      <title>Re: About casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/about-casting/m-p/3819814#M918695</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Narrowing Cast is also known as Upcasting...&lt;/P&gt;&lt;P&gt;Widening Cast is known as Downcasting...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let us take an example...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We define a class lcl_vehicle and other class lcl_truck inherited from lcl_vehicle.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS lcl_vehicle DEFINITION.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;      PUBLIC SECTION.&lt;/P&gt;&lt;P&gt;         METHODS constructor&lt;/P&gt;&lt;P&gt;                   IMPORTING im_make_v  TYPE string.&lt;/P&gt;&lt;P&gt;                   &lt;/P&gt;&lt;P&gt;         METHODS estimate_fuel&lt;/P&gt;&lt;P&gt;                   IMPORTING im_distance   TYPE s_distance&lt;/P&gt;&lt;P&gt;                   RETURNING value(re_fuel) TYPE s_capacity&lt;/P&gt;&lt;P&gt;      &lt;/P&gt;&lt;P&gt;         METHODS get_make........&lt;/P&gt;&lt;P&gt;                                        ........&lt;/P&gt;&lt;P&gt;          &lt;/P&gt;&lt;P&gt;         METHODS get_count........&lt;/P&gt;&lt;P&gt;                                        ........&lt;/P&gt;&lt;P&gt;          METHODS display_attributes........&lt;/P&gt;&lt;P&gt;                                        ........&lt;/P&gt;&lt;P&gt;      PROTECTED SECTION.&lt;/P&gt;&lt;P&gt;          DATA r_tank TYPE REF TO lcl_tank.&lt;/P&gt;&lt;P&gt;      &lt;/P&gt;&lt;P&gt;      PRIVATE SECTION.&lt;/P&gt;&lt;P&gt;          DATA make TYPE string.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;ENDCLASS.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;CLASS lcl_vehicle IMPLEMENTATION.&lt;/P&gt;&lt;P&gt;          &lt;/P&gt;&lt;P&gt;          METHOD constructor.&lt;/P&gt;&lt;P&gt;               make = im_make_v.&lt;/P&gt;&lt;P&gt;          ENDMETHOD.&lt;/P&gt;&lt;P&gt;          METHOD get_make.&lt;/P&gt;&lt;P&gt;             - - - &lt;/P&gt;&lt;P&gt;             - - - &lt;/P&gt;&lt;P&gt;          ENDMETHOD.&lt;/P&gt;&lt;P&gt;          METHOD get_count.&lt;/P&gt;&lt;P&gt;             - - -&lt;/P&gt;&lt;P&gt;             - - -&lt;/P&gt;&lt;P&gt;          ENDMETHOD.&lt;/P&gt;&lt;P&gt;          METHOD display_attributes.&lt;/P&gt;&lt;P&gt;             - - -&lt;/P&gt;&lt;P&gt;             - - -&lt;/P&gt;&lt;P&gt;          ENDMETHOD.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;ENDCLASS.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt; &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 we define a sub class lcl_truck to super class lcl_vehicle.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS lcl_truck DEFINITION INHERITING FROM lcl_vehicle.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;       PUBLIC SECTION.&lt;/P&gt;&lt;P&gt;            METHODS constructor IMPORTING im_make_t TYPE string&lt;/P&gt;&lt;P&gt;                                                         im_cargo_t TYPE s_plan_car&lt;/P&gt;&lt;P&gt;            METHODS estimate_fuel REDEFINITION.&lt;/P&gt;&lt;P&gt;            METHODS get_cargo RETURNING value( re_cargo ) TYPE s_plan_car.&lt;/P&gt;&lt;P&gt;       PRIVATE SECTION.&lt;/P&gt;&lt;P&gt;          DATA max_cargo TYPE s_plan_car.&lt;/P&gt;&lt;P&gt;ENDCLASS.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;CLASS lcl_truck IMPLEMENTATION.&lt;/P&gt;&lt;P&gt;      METHOD constructor.&lt;/P&gt;&lt;P&gt;           CALL METHOD super-&amp;gt;constructor( im_make_v  = im_make_t ).&lt;/P&gt;&lt;P&gt;            max_cargo = im_cargo_t.&lt;/P&gt;&lt;P&gt;      ENDMETHOD.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;      METHOD estimete_fuel.&lt;/P&gt;&lt;P&gt;          DATA total_weight TYPE w_weight.&lt;/P&gt;&lt;P&gt;          total_weight = max_cargo + weight.&lt;/P&gt;&lt;P&gt;          re_fuel = total_weight * im_distance * correction_factor.&lt;/P&gt;&lt;P&gt;       ENDMETHOD.                    &lt;/P&gt;&lt;P&gt;ENDCLASS.&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 we again define one more subclass lcl_bus to superclass lcl_vehicle.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS lcl_bus DEFINITION INHERITING FROM lcl_vehicle.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;PUBLIC SECTION.&lt;/P&gt;&lt;P&gt;            METHODS constructor IMPORTING im_make_b TYPE string&lt;/P&gt;&lt;P&gt;                                                         im_load_b TYPE s_plan_car&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;       PRIVATE SECTION.&lt;/P&gt;&lt;P&gt;          DATA max_load TYPE s_plan_car.&lt;/P&gt;&lt;P&gt;ENDCLASS.  &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;CLASS lcl_bus IMPLEMENTATION.&lt;/P&gt;&lt;P&gt;      METHOD constructor.&lt;/P&gt;&lt;P&gt;           CALL METHOD super-&amp;gt;constructor( im_make_v  = im_make_b ).&lt;/P&gt;&lt;P&gt;            max_cargo = im_load_b.&lt;/P&gt;&lt;P&gt;      ENDMETHOD.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;      METHOD estimete_fuel.&lt;/P&gt;&lt;P&gt;          DATA total_weight TYPE w_weight.&lt;/P&gt;&lt;P&gt;          total_weight = max_passengers * average_weight + weight.&lt;/P&gt;&lt;P&gt;          re_fuel = total_weight * im_distance * correction_factor.&lt;/P&gt;&lt;P&gt;       ENDMETHOD.                    &lt;/P&gt;&lt;P&gt;ENDCLASS. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&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 at runtime.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is called as Narrowing Casting...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lets see how it works...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Creating references to the classes.........&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;DATA:&lt;/P&gt;&lt;P&gt;    r_vehicle TYPE REF TO lcl_vehicle,&lt;/P&gt;&lt;P&gt;    r_truck    TYPE REF TO lcl_truck,&lt;/P&gt;&lt;P&gt;    r_bus      TYPE REF TO lcl_bus.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;*Creating an object of class lcl_truck.........&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;CREATE OBJECT r_truck.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;*Narrowing Cast ................&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;r_vehicle = r_truck.&lt;/P&gt;&lt;P&gt; &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 reference --&amp;gt; superclass.... r_vehicle will point to only the inherited compenents of lcl_truck.&lt;/P&gt;&lt;P&gt;&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 all components that can be accessed syntactically after the cast assignment are actually available in the instance. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The subclass always contains at least the same components as the superclass. After all, the name and the signature of redefined methods are identical. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The user can, therefore, address the subclass instance in the same way as the superclass instance. However, he is restricted to using only the inherited components. In this example, after the assignment, the methods GET_MAKE, GET_COUNT, DISPLAY_ATTRIBUTES and ESTIMATE_FUEL of the instance LCL_TRUCK can only be accessed using the reference R_VEHICLE. If there are any restrictions regarding visibility, they are left unchanged. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is not possible to access the specific components from the class LCL_TRUCK of the instance (GET_CARGO in the above example) using the reference R_VEHICLE. The view is thus usually narrowed (or at least unchanged). That is why we describe this type of assignment of reference variables as narrowing cast. There is a switch from a view of several components to a view of a few components. The term upcast is also common. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A typical use for narrowing cast assignments is to prepare for generic access. A user who is not at all interested in the finer points of the instances of the subclasses but who simply wants to address the shared components could use a superclass reference for this access.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the example shown here, assume that a travel agency (LCL_RENTAL) needs to manage all imaginable kinds of vehicles in one list. This leads to the question of what types should be assigned to the internal table for the references to airplane instances. You should also assume that the car rental company needs to be able to calculate only the required amount of fuel for all its vehicles. Correspondingly, the ESTIMATE_FUEL method is defined in the superclass LCL_VEHICLE and is redefined in all subclasses.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is about Narrowing Cast.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Inspire if this was needful,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;kalyan.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 May 2008 10:21:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/about-casting/m-p/3819814#M918695</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-27T10:21:24Z</dc:date>
    </item>
  </channel>
</rss>

