<?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: Instantiate a ABAP Object Dynamically in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/instantiate-a-abap-object-dynamically/m-p/1732006#M318675</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can instantiate an object dynamically,  here is a sample program.  Notice that we are creating an object passed on what class is named in the selection screen.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

report zrich_0001.

*---------------------------------------------------------------------*
*       CLASS lcl_car DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_car definition.

  public section.

    data: car type string.

endclass.

*---------------------------------------------------------------------*
*       CLASS lcl_car IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_car implementation.

endclass.


*---------------------------------------------------------------------*
*       CLASS lcl_truck DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_truck definition.

  public section.

    data: truck type string.

endclass.

*---------------------------------------------------------------------*
*       CLASS lcl_truck IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_truck implementation.

endclass.


data: r  type ref to object.

parameters: p_class(20) type c default 'LCL_TRUCK'.

start-of-selection.

  create object r type (p_class).

  check sy-subrc = 0.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 07 Dec 2006 18:54:39 GMT</pubDate>
    <dc:creator>RichHeilman</dc:creator>
    <dc:date>2006-12-07T18:54:39Z</dc:date>
    <item>
      <title>Instantiate a ABAP Object Dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/instantiate-a-abap-object-dynamically/m-p/1732005#M318674</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would like to get some guidance on Dynamically instantiating objects within ABAP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have worked with Java.  Within Java I am able to instantiate a Java object through the use Class.forName (see example below):&lt;/P&gt;&lt;P&gt;	&lt;/P&gt;&lt;P&gt;className = "com.vz.it.cleansheet.eFine.db.query.WBRDMTWKCNDATABEAN";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; try {&lt;/P&gt;&lt;P&gt;	singleton = (Object) Class.forName(classname).newInstance();&lt;/P&gt;&lt;P&gt;		&lt;/P&gt;&lt;P&gt;     } catch (ClassNotFoundException cnf) {&lt;/P&gt;&lt;P&gt;			System.out.println("SingletonRegistry - Couldn't find class "}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a similar procedure in ABAP OO to enable dynamically instantiating a ABAP object?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would appreciate any advice.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Rick&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Dec 2006 18:41:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/instantiate-a-abap-object-dynamically/m-p/1732005#M318674</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-12-07T18:41:53Z</dc:date>
    </item>
    <item>
      <title>Re: Instantiate a ABAP Object Dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/instantiate-a-abap-object-dynamically/m-p/1732006#M318675</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can instantiate an object dynamically,  here is a sample program.  Notice that we are creating an object passed on what class is named in the selection screen.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

report zrich_0001.

*---------------------------------------------------------------------*
*       CLASS lcl_car DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_car definition.

  public section.

    data: car type string.

endclass.

*---------------------------------------------------------------------*
*       CLASS lcl_car IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_car implementation.

endclass.


*---------------------------------------------------------------------*
*       CLASS lcl_truck DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_truck definition.

  public section.

    data: truck type string.

endclass.

*---------------------------------------------------------------------*
*       CLASS lcl_truck IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_truck implementation.

endclass.


data: r  type ref to object.

parameters: p_class(20) type c default 'LCL_TRUCK'.

start-of-selection.

  create object r type (p_class).

  check sy-subrc = 0.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Dec 2006 18:54:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/instantiate-a-abap-object-dynamically/m-p/1732006#M318675</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2006-12-07T18:54:39Z</dc:date>
    </item>
    <item>
      <title>Re: Instantiate a ABAP Object Dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/instantiate-a-abap-object-dynamically/m-p/1732007#M318676</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Check this sample as well.  I hope it helped you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;REPORT  ZOO.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      CLASS counter DEFINITION&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS COUNTER DEFINITION.&lt;/P&gt;&lt;P&gt;  PUBLIC SECTION.&lt;/P&gt;&lt;P&gt;    METHODS INCREMENT.&lt;/P&gt;&lt;P&gt;  PRIVATE SECTION.&lt;/P&gt;&lt;P&gt;    DATA COUNT TYPE I.&lt;/P&gt;&lt;P&gt;ENDCLASS.                    "counter DEFINITION&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      CLASS counter IMPLEMENTATION&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS COUNTER IMPLEMENTATION.&lt;/P&gt;&lt;P&gt;  METHOD INCREMENT.&lt;/P&gt;&lt;P&gt;    COUNT = COUNT + 1.&lt;/P&gt;&lt;P&gt;    WRITE:/ 'The Count is:', COUNT.&lt;/P&gt;&lt;P&gt;  ENDMETHOD.                    "increment&lt;/P&gt;&lt;P&gt;ENDCLASS.                    "counter IMPLEMENTATION&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA COUNT TYPE REF TO COUNTER.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;START-OF-SELECTION.&lt;/P&gt;&lt;P&gt;  CREATE OBJECT COUNT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  DO 5 TIMES.&lt;/P&gt;&lt;P&gt;    CALL METHOD COUNT-&amp;gt;INCREMENT.&lt;/P&gt;&lt;P&gt;  ENDDO.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Ramki.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Dec 2006 10:55:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/instantiate-a-abap-object-dynamically/m-p/1732007#M318676</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-12-11T10:55:23Z</dc:date>
    </item>
  </channel>
</rss>

