<?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 Help in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting-help/m-p/4466042#M1058124</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;  '?=' This is widening cast operator. in your example you have assigned instance of superclass to instance of subclass. &lt;/P&gt;&lt;P&gt;After this assignment, you can access the specific components of subclass lcl_cargo_plane using instance r_cargo.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&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;I would like to add one more point that &lt;/P&gt;&lt;P&gt;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&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 08 Sep 2008 10:30:43 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-09-08T10:30:43Z</dc:date>
    <item>
      <title>Casting Help</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting-help/m-p/4466038#M1058120</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;i learn OO and maybe someone can explain me &lt;/P&gt;&lt;P&gt;what is the action  in bold is doing ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;r_cargo &lt;STRONG&gt;?=&lt;/STRONG&gt; r_plane.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; Regards &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;   DATA: r_cargo TYPE REF TO lcl_cargo_plane.&lt;/P&gt;&lt;P&gt;    DATA: r_plane TYPE REF TO lcl_airplane.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    LOOP AT airplane_list INTO r_plane.&lt;/P&gt;&lt;P&gt;      TRY.&lt;/P&gt;&lt;P&gt;          r_cargo &lt;STRONG&gt;?=&lt;/STRONG&gt; r_plane.&lt;/P&gt;&lt;P&gt;          cargo = r_cargo-&amp;gt;get_cargo( ).&lt;/P&gt;&lt;P&gt;          IF re_cargo &amp;lt; cargo.&lt;/P&gt;&lt;P&gt;            re_cargo = cargo.&lt;/P&gt;&lt;P&gt;          ENDIF.&lt;/P&gt;&lt;P&gt;        CATCH cx_sy_move_cast_error INTO r_exc.&lt;/P&gt;&lt;P&gt;      ENDTRY&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Sep 2008 09:47:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/casting-help/m-p/4466038#M1058120</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-09-08T09:47:35Z</dc:date>
    </item>
    <item>
      <title>Re: Casting Help</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting-help/m-p/4466039#M1058121</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;Its nothing but Wide casting Concept in OOABAP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;In short you are increasing the scope of accessibility of that object.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;*Lets say there are two classes CLASS A and CLASS B.*

*Class B inherits CLASS A..*

*So you had created object for CLASS A and you had just delcared object for CLASS B.*
*So now to increase the scope of the CLASS B object we can use Wide-casting concept..*

*DATA:*
  *W_ref_A type REF TO CLASS A,*
  *W_REF_B type REF TO CLASS B.*

*Create object CLASS A.*
*-------------------------*
*After some logic (optional)*
*-------------------------*

*W_REF_B ?= W_REF_A.  " Wide casting..*

*By Wide-casting the scope increases like with W_REF_A you cannot access the other methods define* 
*in class B other than inherited methods but using W_REF_B you can access as it is reference to Class B.*&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check these threads for more details..&lt;/P&gt;&lt;P&gt;&lt;A class="jive_macro jive_macro_thread" href="https://community.sap.com/" __jive_macro_name="thread" modifiedtitle="true" __default_attr="313275"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this would solve your issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck&lt;/P&gt;&lt;P&gt;Narin&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Narin Nandivada on Sep 8, 2008 3:26 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Sep 2008 09:49:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/casting-help/m-p/4466039#M1058121</guid>
      <dc:creator>narin_nandivada3</dc:creator>
      <dc:date>2008-09-08T09:49:08Z</dc:date>
    </item>
    <item>
      <title>Re: Casting Help</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting-help/m-p/4466040#M1058122</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;?= is Wide casting or down cast&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Sep 2008 10:03:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/casting-help/m-p/4466040#M1058122</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-09-08T10:03:02Z</dc:date>
    </item>
    <item>
      <title>Re: Casting Help</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting-help/m-p/4466041#M1058123</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;for additional information please check this thread&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="5774795"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check this link &lt;/P&gt;&lt;P&gt;&lt;A href="http://www.abapprogramming.net/2007/10/oops-abap-8.html" target="test_blank"&gt;http://www.abapprogramming.net/2007/10/oops-abap-8.html&lt;/A&gt;&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;Good luck&lt;/P&gt;&lt;P&gt;Narin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Sep 2008 10:06:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/casting-help/m-p/4466041#M1058123</guid>
      <dc:creator>narin_nandivada3</dc:creator>
      <dc:date>2008-09-08T10:06:36Z</dc:date>
    </item>
    <item>
      <title>Re: Casting Help</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting-help/m-p/4466042#M1058124</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;  '?=' This is widening cast operator. in your example you have assigned instance of superclass to instance of subclass. &lt;/P&gt;&lt;P&gt;After this assignment, you can access the specific components of subclass lcl_cargo_plane using instance r_cargo.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&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;I would like to add one more point that &lt;/P&gt;&lt;P&gt;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&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Sep 2008 10:30:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/casting-help/m-p/4466042#M1058124</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-09-08T10:30:43Z</dc:date>
    </item>
    <item>
      <title>Re: Casting Help</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting-help/m-p/4466043#M1058125</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Narin,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks but maybe u can explain me this code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cl_abap_typedescr is class interface &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA: gx_struc TYPE REF TO cl_abap_structdescr.
  DATA: gx_table TYPE REF TO cl_abap_tabledescr.

  gx_table ?= cl_abap_typedescr=&amp;gt;describe_by_data( &amp;lt;col_actual&amp;gt; )."--Get Table Colman Numbers--*
  gx_struc ?= gx_table-&amp;gt;get_table_line_type( ).
  DESCRIBE TABLE gx_struc-&amp;gt;components LINES t_lines.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Sep 2008 11:21:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/casting-help/m-p/4466043#M1058125</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-09-08T11:21:44Z</dc:date>
    </item>
    <item>
      <title>Re: Casting Help</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting-help/m-p/4466044#M1058126</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;As CL_ABAP_TYPEDESCR is an Abstract class having the static method as DESCRIBE_BY_DATA. &lt;/P&gt;&lt;P&gt;and its  RETURNING parameter is typed as a reference to this superclass. since the actual parameter &lt;/P&gt;&lt;P&gt;gx_table  is typed on the subclass CL_ABAP_STRUCTDESCR, so the object has to be assigned using &lt;/P&gt;&lt;P&gt;Widening Cast with operator ?= .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please check this document which would give your more clear idea...&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/f2dac69e-0e01-0010-e2b6-81c1e8e5ce50" target="test_blank"&gt;https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/f2dac69e-0e01-0010-e2b6-81c1e8e5ce50&lt;/A&gt;&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;Good luck&lt;/P&gt;&lt;P&gt;Narin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Sep 2008 15:33:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/casting-help/m-p/4466044#M1058126</guid>
      <dc:creator>narin_nandivada3</dc:creator>
      <dc:date>2008-09-08T15:33:51Z</dc:date>
    </item>
  </channel>
</rss>

