<?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 Variable assignment inconsistency in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/variable-assignment-inconsistency/m-p/7475604#M1555592</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi expers &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have have a question about variable assigement&lt;/P&gt;&lt;P&gt;Here are my variables declared.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
data: a_sofm_document    TYPE REF TO cl_document_bcs,
         an_if_document     TYPE REF TO if_document_bcs,
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;This portion of code works perpectly&lt;/STRONG&gt; &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
a_sofm_document = cl_document_bcs=&amp;gt;create_from_text( i_text = xt i_subject = subject )
an_if_document = a_sofm_document.   
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Try to assign back from  an_if_document&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
a_sofm_document  = an_if_document .  " Doest not work and generate error when compiling
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Somebody understand why ?? and How to obtain a_sofm_document back?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 26 Nov 2010 19:04:53 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2010-11-26T19:04:53Z</dc:date>
    <item>
      <title>Variable assignment inconsistency</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/variable-assignment-inconsistency/m-p/7475604#M1555592</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi expers &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have have a question about variable assigement&lt;/P&gt;&lt;P&gt;Here are my variables declared.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
data: a_sofm_document    TYPE REF TO cl_document_bcs,
         an_if_document     TYPE REF TO if_document_bcs,
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;This portion of code works perpectly&lt;/STRONG&gt; &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
a_sofm_document = cl_document_bcs=&amp;gt;create_from_text( i_text = xt i_subject = subject )
an_if_document = a_sofm_document.   
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Try to assign back from  an_if_document&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
a_sofm_document  = an_if_document .  " Doest not work and generate error when compiling
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Somebody understand why ?? and How to obtain a_sofm_document back?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Nov 2010 19:04:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/variable-assignment-inconsistency/m-p/7475604#M1555592</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-11-26T19:04:53Z</dc:date>
    </item>
    <item>
      <title>Re: Variable assignment inconsistency</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/variable-assignment-inconsistency/m-p/7475605#M1555593</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;an_if_document    of type  if_document_bcs is a superior type to cl_document_bcs&lt;/P&gt;&lt;P&gt;Thise means you need to downcast:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;a_sofm_document  ?= an_if_document&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but ths is not a good programming practice. From OO perspective you should never need to do something like this.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 27 Nov 2010 10:21:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/variable-assignment-inconsistency/m-p/7475605#M1555593</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-11-27T10:21:29Z</dc:date>
    </item>
    <item>
      <title>Re: Variable assignment inconsistency</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/variable-assignment-inconsistency/m-p/7475606#M1555594</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dominik,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but ths is not a good programming practice. From OO perspective you should never need to do something like this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I must strongly disagree here. The basic usage is in combination with &lt;EM&gt;polimorphism&lt;/EM&gt; . Imagine we have a container type as ref to some superclass. We store there a number of subclasses' references, treating them generically i.e. calling same poliphormical method for each. Now we want some specific operation to objects of only certain type. Downcasting here is ideal for such operation. This would go like&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
loop at me-&amp;gt;ref_container into r_vehicle.
   try.
      r_plane ?= r_vehicle.
       "do addtional calc. only for planes
       ...
   catch cx_sy_move_cast_error.
endloop.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Another example would be RTTS classes where from superclass &lt;EM&gt;cl_abap_typedescr&lt;/EM&gt; we derive some specialized one i.e&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
data r_tabledescr type ref to cl_abap_structdescr.

r_tabledescr ?= cl_abap_typedescr=&amp;gt;describe_by_data( itab ).
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I think these proves downcasting is not only very important aspect of OO design but also let us smoothly switch b/w generalization and specialization which often is required to achieve some kind of functionality.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any comments are welcome:)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Marcin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 27 Nov 2010 21:13:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/variable-assignment-inconsistency/m-p/7475606#M1555594</guid>
      <dc:creator>MarcinPciak</dc:creator>
      <dc:date>2010-11-27T21:13:18Z</dc:date>
    </item>
    <item>
      <title>Re: Variable assignment inconsistency</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/variable-assignment-inconsistency/m-p/7475607#M1555595</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Marcin,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;happy to oblige &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;as Dominik says &lt;EM&gt;never&lt;/EM&gt; without proof, my feeling is: [Absolutism|http://c2.com/cgi-bin/wiki?AbsolutismHasGreaterBurdenOfProof], he might be wrong. But..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;your special code for a concrete &lt;EM&gt;plane&lt;/EM&gt; class violates the [program to an interface, not an implementation|http://sourcemaking.com/design_patterns/strategy] principle. My feeling is: design smell !&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your second example should work fine without the knowledge of the subclass created by the factory method, i.e. with the definition  &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;r_tabledescr TYPE REF TO cl_abap_typedescr.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I do not see why [Liskov's Substitution|http://c2.com/cgi-bin/wiki?LiskovSubstitutionPrinciple] should not apply. So the downcasting is not needed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;my vote: neither you nor Dominik have proof. &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;J.N.N&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 27 Nov 2010 23:48:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/variable-assignment-inconsistency/m-p/7475607#M1555595</guid>
      <dc:creator>nomssi</dc:creator>
      <dc:date>2010-11-27T23:48:01Z</dc:date>
    </item>
    <item>
      <title>Re: Variable assignment inconsistency</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/variable-assignment-inconsistency/m-p/7475608#M1555596</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks a a lot experts, You are so helpful to me. Downcasting works for me even that I do not yet unsertand why. My time is limited and somtimes  make it work is the first priority in special cirumstanses, I wish that I could attribute points to all eqauly. Will have to to do a learning curve on OO.&lt;/P&gt;&lt;P&gt;Again thanks a lot&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Nov 2010 15:16:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/variable-assignment-inconsistency/m-p/7475608#M1555596</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-11-29T15:16:42Z</dc:date>
    </item>
  </channel>
</rss>

