<?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 Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting/m-p/3172185#M754828</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Refer the links -&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="1850993"&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="2971785"&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="4388544"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amit&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward all helpful replies.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 10 Dec 2007 08:41:59 GMT</pubDate>
    <dc:creator>amit_khare</dc:creator>
    <dc:date>2007-12-10T08:41:59Z</dc:date>
    <item>
      <title>Casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting/m-p/3172184#M754827</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What is the concept of casting in ABAP?&lt;/P&gt;&lt;P&gt;what is the difference between UP CAST &amp;amp; DOWN CAST?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;Sharayu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Dec 2007 08:40:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/casting/m-p/3172184#M754827</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-12-10T08:40:20Z</dc:date>
    </item>
    <item>
      <title>Re: Casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting/m-p/3172185#M754828</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Refer the links -&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="1850993"&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="2971785"&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="4388544"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amit&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward all helpful replies.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Dec 2007 08:41:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/casting/m-p/3172185#M754828</guid>
      <dc:creator>amit_khare</dc:creator>
      <dc:date>2007-12-10T08:41:59Z</dc:date>
    </item>
    <item>
      <title>Re: Casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting/m-p/3172186#M754829</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&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;&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;Keep fighting and win the race.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Dec 2007 08:43:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/casting/m-p/3172186#M754829</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-12-10T08:43:00Z</dc:date>
    </item>
    <item>
      <title>Re: Casting</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting/m-p/3172187#M754830</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;The following sample report ZUS_SDN_CL_PO_HEADER_HNDL shows you how to use casting (into different interface reference types) is used to access the specific methods of a purchase order.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp; Report  ZUS_SDN_CL_PO_HEADER_HNDL
*&amp;amp;
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;
*&amp;amp;
*&amp;amp;---------------------------------------------------------------------*
 
REPORT  zus_sdn_cl_po_header_hndl.
 
 
TABLES:  ekko.
 
 
DATA:
  go_po_header      TYPE REF TO cl_po_header_handle_mm,
  go_po_doc         TYPE REF TO if_purchasing_document,
  go_po_partner     TYPE REF TO if_partners_mm.
 
 
DATA:
  gt_partner        TYPE mmpur_partner_all_tab,
  gt_partner_ext    TYPE mmpur_partner_tab.
 
PARAMETERS:
  p_ebeln           TYPE ekko-ebeln  DEFAULT '4500016345'.
 
START-OF-SELECTION.
 
" Create purchase order instance (header)
  CREATE OBJECT go_po_header
    EXPORTING
      im_po_number = p_ebeln
    EXCEPTIONS
      failure = 1
      OTHERS  = 2.
  IF sy-subrc &amp;lt;&amp;gt; 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
  CHECK ( go_po_header IS BOUND ).
 
 
  " Casting into document related instance
  go_po_doc ?= go_po_header.
 
  gt_partner = go_po_doc-&amp;gt;get_partners( ).
  gt_partner = go_po_header-&amp;gt;if_purchasing_document~get_partners( ).
**  gt_partner = go_po_header-&amp;gt;get_partners( ).  " not possible
 
 
 
  " Casting into partner related instance
  go_po_partner ?= go_po_header.
 
  CALL METHOD go_po_partner-&amp;gt;get_data
    IMPORTING
      ext_partners = gt_partner_ext.
  CALL METHOD go_po_header-&amp;gt;if_partners_mm~get_data
    IMPORTING
      ext_partners = gt_partner_ext.
**  CALL METHOD go_po_header-&amp;gt;get_data
**    IMPORTING
**      ext_partners = gt_partner_ext.  " not possible
 
 
END-OF-SELECTION.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Omkar.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Dec 2007 08:49:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/casting/m-p/3172187#M754830</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-12-10T08:49:39Z</dc:date>
    </item>
  </channel>
</rss>

