<?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: Widening casting-code in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/widening-casting-code/m-p/7970391#M1603700</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am referring to taw10_3 material,in which they say&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;more_gen = less_gener---&amp;gt;narrow cast,  since then,acces of more_gen  is limited to shared comp.only&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;less_gen ?= more_general---widening cast&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Amnt sure whether they renamed the terminology(widening and narrow).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here my doubt wasnt what is narrow and widening.i&lt;/P&gt;&lt;P&gt;But i  could use the ?=,operator for assigning a less_gen to a more_gen ref.variable.why?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 13 Jun 2011 08:17:36 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2011-06-13T08:17:36Z</dc:date>
    <item>
      <title>Widening casting-code</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/widening-casting-code/m-p/7970389#M1603698</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;class parent definition.&lt;/P&gt;&lt;P&gt;  public section.&lt;/P&gt;&lt;P&gt;  data pub_parent type i.&lt;/P&gt;&lt;P&gt;  endclass.&lt;/P&gt;&lt;P&gt;  class child definition inheriting from parent.&lt;/P&gt;&lt;P&gt;    public section.&lt;/P&gt;&lt;P&gt;    data pc type i.&lt;/P&gt;&lt;P&gt;    endclass.&lt;/P&gt;&lt;P&gt;    data parent type ref to parent.&lt;/P&gt;&lt;P&gt;    data child type ref to child.&lt;/P&gt;&lt;P&gt;    data child1 type ref to child.&lt;/P&gt;&lt;P&gt;create object child.&lt;/P&gt;&lt;P&gt;create object parent.&lt;/P&gt;&lt;P&gt;    try.&lt;/P&gt;&lt;P&gt;      parent ?= child.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      catch cx_sy_move_cast_error.&lt;/P&gt;&lt;P&gt;        write 'error'.&lt;/P&gt;&lt;P&gt;        endtry.&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-------------------------------------------" /&gt;&lt;P&gt;Hi all &lt;/P&gt;&lt;P&gt;code snippet above doesnt gives me any error..I am doing narrow casting here with a widening cast operator ?=.does that mean ,when it comes to narrow casting u can use either = or ?=.it doesnt make any difference?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Jun 2011 09:35:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/widening-casting-code/m-p/7970389#M1603698</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-06-11T09:35:44Z</dc:date>
    </item>
    <item>
      <title>Re: Widening casting-code</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/widening-casting-code/m-p/7970390#M1603699</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;widening cast : more_general = less_general&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;narrowing cast : less_general ?= more_general&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Jun 2011 15:58:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/widening-casting-code/m-p/7970390#M1603699</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2011-06-11T15:58:15Z</dc:date>
    </item>
    <item>
      <title>Re: Widening casting-code</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/widening-casting-code/m-p/7970391#M1603700</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am referring to taw10_3 material,in which they say&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;more_gen = less_gener---&amp;gt;narrow cast,  since then,acces of more_gen  is limited to shared comp.only&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;less_gen ?= more_general---widening cast&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Amnt sure whether they renamed the terminology(widening and narrow).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here my doubt wasnt what is narrow and widening.i&lt;/P&gt;&lt;P&gt;But i  could use the ?=,operator for assigning a less_gen to a more_gen ref.variable.why?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Jun 2011 08:17:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/widening-casting-code/m-p/7970391#M1603700</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-06-13T08:17:36Z</dc:date>
    </item>
    <item>
      <title>Re: Widening casting-code</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/widening-casting-code/m-p/7970392#M1603701</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'll try to explain this using an example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA: go1 TYPE REF TO object,      "More generic
      go2 TYPE REF TO zcl_myclass. "Less generic&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you try to assign a 'more-generic' ref. to a 'less generic' ref., the static check performed by the compiler throws a compilation error.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;* Assign a more generic ref. to less generic ref.
go2 = go1.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The compiler checks the static types of &lt;EM&gt;go1&lt;/EM&gt; &amp;amp; &lt;EM&gt;go2&lt;/EM&gt; and since the assignment is not compatible(more generic is being assigned to less generic) syntax error is raised.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The casting operator '?=' is a kind of instruction to the compiler to skip the static check &amp;amp; perform the checks during runtime!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;CREATE OBJECT go1 TYPE zcl_myclass.

TRY .
* Static compiler check is skipped. The compatibility is checked only
* at runtime
    go2 ?= go1.
    MESSAGE 'Casting is successful' TYPE 'S'.
  CATCH cx_sy_move_cast_error.
    MESSAGE 'Error in casting' TYPE 'E'.
ENDTRY.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The compiler checks the type of &lt;EM&gt;go1&lt;/EM&gt; at runtime &amp;amp; since the assignment is compatible no exception is raised.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Consider this example, the exception CX_SY_MOVE_CAST_ERROR is raised at runtime since the dynamic types are not compatible!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA: gx_err  TYPE REF TO cx_sy_move_cast_error,
      gv_msg  TYPE string.

CREATE OBJECT go1 TYPE zcl_airlines.

TRY .
* Static compiler check is skipped. The compatibility is checked only
* at runtime
    go2 ?= go1.
    MESSAGE 'Casting is successful' TYPE 'S'.
  CATCH cx_sy_move_cast_error INTO gx_err.
    gv_msg = gx_err-&amp;gt;get_text( ).
    MESSAGE gv_msg TYPE 'S'.
ENDTRY.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;But i could use the ?=,operator for assigning a less_gen to a more_gen ref.variable.why?&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The casting operator '?=' can be used for both &lt;EM&gt;narrowing&lt;/EM&gt; as well as &lt;EM&gt;widening&lt;/EM&gt; cast. But in case of &lt;EM&gt;widening&lt;/EM&gt; cast, its use is redundant.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope you get my point.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BR,&lt;/P&gt;&lt;P&gt;Suhas&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Suhas Saha on Jun 13, 2011 5:16 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Jun 2011 11:41:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/widening-casting-code/m-p/7970392#M1603701</guid>
      <dc:creator>SuhaSaha</dc:creator>
      <dc:date>2011-06-13T11:41:25Z</dc:date>
    </item>
  </channel>
</rss>

