<?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 Calling method of object whose type is not known until runtime in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/calling-method-of-object-whose-type-is-not-known-until-runtime/m-p/1948928#M390943</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hiya,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In SE80 class builder I have attribute R_OBJECT TYPE REF TO OBJECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In my CONSTRUCTOR method, I do a:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CREATE OBJECT R_OBJECT TYPE (lc_variable)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;,where lc_variable contains type I want to use.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This seems to compile, but when I try to call a method using the following statement, the compiler complains saying that the method is not known.  Well, of course it's not known, I haven't told it which class the object belongs to yet!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CALL METHOD R_OBJECT-&amp;gt;MY_METHOD RECEIVING lc_result.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What am I doing wrong?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tristan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 19 Feb 2007 04:33:52 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-02-19T04:33:52Z</dc:date>
    <item>
      <title>Calling method of object whose type is not known until runtime</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/calling-method-of-object-whose-type-is-not-known-until-runtime/m-p/1948928#M390943</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hiya,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In SE80 class builder I have attribute R_OBJECT TYPE REF TO OBJECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In my CONSTRUCTOR method, I do a:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CREATE OBJECT R_OBJECT TYPE (lc_variable)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;,where lc_variable contains type I want to use.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This seems to compile, but when I try to call a method using the following statement, the compiler complains saying that the method is not known.  Well, of course it's not known, I haven't told it which class the object belongs to yet!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CALL METHOD R_OBJECT-&amp;gt;MY_METHOD RECEIVING lc_result.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What am I doing wrong?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tristan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Feb 2007 04:33:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/calling-method-of-object-whose-type-is-not-known-until-runtime/m-p/1948928#M390943</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-02-19T04:33:52Z</dc:date>
    </item>
    <item>
      <title>Re: Calling method of object whose type is not known until runtime</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/calling-method-of-object-whose-type-is-not-known-until-runtime/m-p/1948929#M390944</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Tristan&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The &amp;lt;b&amp;gt;static&amp;lt;/b&amp;gt; type of r_object is OBJECT and, therefore, will never have any methods you have defined. In order to call your method you must do &amp;lt;b&amp;gt;narrow casting&amp;lt;/b&amp;gt;, e.g:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA:
  lo_myclass     TYPE REF TO &amp;lt;lc_variable&amp;gt;.  " your class


CREATE OBJECT R_OBJECT TYPE (lc_variable).

* Narrow casting required
  lo_myclass ?= r_object.

  lc_result = lo_myclass-&amp;gt;my_method( ).  " now it works&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;  Uwe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Feb 2007 10:59:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/calling-method-of-object-whose-type-is-not-known-until-runtime/m-p/1948929#M390944</guid>
      <dc:creator>uwe_schieferstein</dc:creator>
      <dc:date>2007-02-19T10:59:24Z</dc:date>
    </item>
  </channel>
</rss>

