<?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 using a generic object in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-a-generic-object/m-p/851660#M46307</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would like to be able to create an instance of an ABAP object without knowing the object type first. for example, if a specific type of message hits a queue, create a handler object specific to that message. I need to be able to declare the object variable as something not strongly typed, and do the create object for whatever actual object i want to use. I have checked the docs, but found nothing.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 23 Dec 2004 18:20:22 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2004-12-23T18:20:22Z</dc:date>
    <item>
      <title>using a generic object</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-a-generic-object/m-p/851660#M46307</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would like to be able to create an instance of an ABAP object without knowing the object type first. for example, if a specific type of message hits a queue, create a handler object specific to that message. I need to be able to declare the object variable as something not strongly typed, and do the create object for whatever actual object i want to use. I have checked the docs, but found nothing.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Dec 2004 18:20:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-a-generic-object/m-p/851660#M46307</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2004-12-23T18:20:22Z</dc:date>
    </item>
    <item>
      <title>Re: using a generic object</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-a-generic-object/m-p/851661#M46308</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello David,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I have understood your requirement correctly, then I think it is possible to meet it. Consider the following example :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

data w_obj type ref to object.
data meth(5) type c value 'WRITE'.

class test definition.
  public section.
    data:
      lv_test_variable type c value 'A'.
    methods write.
endclass.

class test implementation.
  method write.
    write:
        lv_test_variable,
        'Simple Sample'.
  endmethod.
endclass.

start-of-selection.

create object w_obj type test.

call method w_obj-&amp;gt;(meth).
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As you are sure to discover, this approach has some limitations. I have not studied this thoroughly, but at least you can begin thinking in the lines of creating Object References.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this has been of some help to you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Anand Mandalika.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Dec 2004 05:17:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-a-generic-object/m-p/851661#M46308</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2004-12-24T05:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: using a generic object</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-a-generic-object/m-p/851662#M46309</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;Take a look at the document https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/a1-8-4/advanced and generic programming in abap.pdf and the webcast titled &amp;lt;b&amp;gt;Advanced and Generic Programming in ABAP&amp;lt;/b&amp;gt; in the SAP TechEd Education Sessions available on SDN. It will help you in getting an idea about runtime type specification. The book Abap Objects gives a detailed description of the concepts as well.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If your prgram is using inheritance/interfaces, you can use polymorphism to achieve your purpose. Otherwise, take a look at the documentation for &amp;lt;b&amp;gt;CREATE DATA dref TYPE REF TO type|(typename)&amp;lt;/b&amp;gt; and cl_abap_refdesc=&amp;gt;create_by_name( 'CLASS_NAME' )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&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;Message was edited by: Shehryar Khan&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Dec 2004 06:00:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-a-generic-object/m-p/851662#M46309</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2004-12-24T06:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: using a generic object</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-a-generic-object/m-p/851663#M46310</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi David,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think this feature can be achieved only in WAS 6.40. ( Someone correct me here, if I am wrong ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This syntax is available, perhaps only in 6.40 WAS, and didn't work in 4.6C.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
CREATE DATA dref TYPE HANDLE &amp;lt;class_name&amp;gt;.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since, I do not have 6.40 WAS, I will give a shot-in-the-dark solution:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
data: lv_variable(25) type c value 'CL_GUI_ALV_GRID'.
data: myref type ref to data.

field-symbols: &amp;lt;FS&amp;gt; type any.

assign lv_variable to &amp;lt;fs&amp;gt;.
if sy-subrc = 0.
  create data myref type handle &amp;lt;fs&amp;gt;.
endif.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I do not guarantee this will work, but with the document link, which Shehryar Khan has given in the previous post, I am guessing this should work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If it works, then you can create an object at runtime, of any classname.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Subramanian V.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Dec 2004 06:18:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-a-generic-object/m-p/851663#M46310</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2004-12-24T06:18:09Z</dc:date>
    </item>
    <item>
      <title>Re: using a generic object</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-a-generic-object/m-p/851664#M46311</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 statements &amp;lt;b&amp;gt;DATA &amp;lt;dref&amp;gt; TYPE REF TO DATA&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;CREATE DATA &amp;lt;dref&amp;gt; TYPE &amp;lt;type&amp;gt;|LIKE &amp;lt;obj&amp;gt;&amp;lt;/b&amp;gt; are available since ver 4.6. So creating a data/object reference dynamically and calling its methods should not be an issue even in versions earlier than 6.40. The HANDLE addition perhaps requires a newer version.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Dec 2004 07:12:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-a-generic-object/m-p/851664#M46311</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2004-12-24T07:12:10Z</dc:date>
    </item>
    <item>
      <title>Re: using a generic object</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-a-generic-object/m-p/851665#M46312</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Shehryar. I was aware of that. I was only concerned about the 'HANDLE' clause.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Subramanian V.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Dec 2004 07:14:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-a-generic-object/m-p/851665#M46312</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2004-12-24T07:14:48Z</dc:date>
    </item>
  </channel>
</rss>

