<?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: instance of class in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/instance-of-class/m-p/3040363#M719542</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jayakumar,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've alread answered this question on SDN Forum, you can see here que this &lt;A class="jive_macro jive_macro_thread" href="https://community.sap.com/" __jive_macro_name="thread" modifiedtitle="true" __default_attr="618994"&gt;&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You need control this in the class as the follow example.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
*----------------------------------------------------------------------*
*       CLASS one DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS one DEFINITION CREATE PRIVATE.
 
  PUBLIC SECTION.
 
    CLASS-METHODS create_objects EXPORTING obj_ref TYPE REF TO one.
 
    CLASS-METHODS clear_objects.
 
  PROTECTED SECTION.
 
  PRIVATE SECTION.
 
    CLASS-DATA obj_one TYPE REF TO one.
 
ENDCLASS.                    "one DEFINITION
 
 
*----------------------------------------------------------------------*
*       CLASS one IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS one IMPLEMENTATION.
 
  METHOD create_objects.
 
    IF obj_one IS INITIAL.
      " Create a new instance
      CREATE OBJECT obj_one.
      MOVE obj_one TO obj_ref.
    ELSE.
      " Use an existing instance
      MOVE obj_one TO obj_ref.
    ENDIF.
 
  ENDMETHOD.                    "create_objects
 
  METHOD clear_objects.
 
    CLEAR obj_one.
 
  ENDMETHOD.                    "clear_objects
 
ENDCLASS.                    "one IMPLEMENTATION
 
DATA: obj1 TYPE REF TO one,
      obj2 TYPE REF TO one.
 
START-OF-SELECTION.
 
" Now you'll create the first instance for your class
  CALL METHOD one=&amp;gt;create_objects
    IMPORTING
      obj_ref                = obj1.
 
" Now you'll use an existing instance
  CALL METHOD one=&amp;gt;create_objects
    IMPORTING
      obj_ref                = obj2.
  
  CLEAR obj1.
  one=&amp;gt;clear_objects( ).
  
" Now you'll be able to create a new instance for your class
  CALL METHOD one=&amp;gt;create_objects
    IMPORTING
      obj_ref                = obj2.
 
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I Hope it's usefull for you !&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;Marcelo Ramos&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 12 Nov 2007 14:10:30 GMT</pubDate>
    <dc:creator>marcelo_ramos1</dc:creator>
    <dc:date>2007-11-12T14:10:30Z</dc:date>
    <item>
      <title>instance of class</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/instance-of-class/m-p/3040360#M719539</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi all ,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i need to check wheather instance for a particular class is already created or not .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i will be passing the class name and i need the result.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks and regards.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;JK&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Nov 2007 11:42:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/instance-of-class/m-p/3040360#M719539</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-11-12T11:42:03Z</dc:date>
    </item>
    <item>
      <title>Re: instance of class</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/instance-of-class/m-p/3040361#M719540</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Jayakumar&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I assume you want to check whether your reference variable hold an instance already. There are two ways available:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
DATA:
  lo_myref    TYPE REF TO &amp;lt;class name / interface name&amp;gt;.


  IF ( lo_myref IS INITIAL ).

  ELSE.
"   we have an instance
  ENDIF.


" Since SAP release &amp;gt;= 6.20 a more specific statement is available:
  IF ( lo_myref IS BOUND ).
"   we have an instance
  ELSE.

  ENDIF.&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;  Uwe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Nov 2007 12:06:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/instance-of-class/m-p/3040361#M719540</guid>
      <dc:creator>uwe_schieferstein</dc:creator>
      <dc:date>2007-11-12T12:06:25Z</dc:date>
    </item>
    <item>
      <title>Re: instance of class</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/instance-of-class/m-p/3040362#M719541</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;no its not like this ..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i have a constructor in the class.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so when i create instance for this class the constructor is fired .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;in the constructor i need to check weather an instance has been already created or not .&lt;/P&gt;&lt;P&gt;if its created i will take the reference from that &lt;/P&gt;&lt;P&gt;if its not created then i will allow to create new instance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Nov 2007 13:28:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/instance-of-class/m-p/3040362#M719541</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-11-12T13:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: instance of class</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/instance-of-class/m-p/3040363#M719542</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jayakumar,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've alread answered this question on SDN Forum, you can see here que this &lt;A class="jive_macro jive_macro_thread" href="https://community.sap.com/" __jive_macro_name="thread" modifiedtitle="true" __default_attr="618994"&gt;&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You need control this in the class as the follow example.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
*----------------------------------------------------------------------*
*       CLASS one DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS one DEFINITION CREATE PRIVATE.
 
  PUBLIC SECTION.
 
    CLASS-METHODS create_objects EXPORTING obj_ref TYPE REF TO one.
 
    CLASS-METHODS clear_objects.
 
  PROTECTED SECTION.
 
  PRIVATE SECTION.
 
    CLASS-DATA obj_one TYPE REF TO one.
 
ENDCLASS.                    "one DEFINITION
 
 
*----------------------------------------------------------------------*
*       CLASS one IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS one IMPLEMENTATION.
 
  METHOD create_objects.
 
    IF obj_one IS INITIAL.
      " Create a new instance
      CREATE OBJECT obj_one.
      MOVE obj_one TO obj_ref.
    ELSE.
      " Use an existing instance
      MOVE obj_one TO obj_ref.
    ENDIF.
 
  ENDMETHOD.                    "create_objects
 
  METHOD clear_objects.
 
    CLEAR obj_one.
 
  ENDMETHOD.                    "clear_objects
 
ENDCLASS.                    "one IMPLEMENTATION
 
DATA: obj1 TYPE REF TO one,
      obj2 TYPE REF TO one.
 
START-OF-SELECTION.
 
" Now you'll create the first instance for your class
  CALL METHOD one=&amp;gt;create_objects
    IMPORTING
      obj_ref                = obj1.
 
" Now you'll use an existing instance
  CALL METHOD one=&amp;gt;create_objects
    IMPORTING
      obj_ref                = obj2.
  
  CLEAR obj1.
  one=&amp;gt;clear_objects( ).
  
" Now you'll be able to create a new instance for your class
  CALL METHOD one=&amp;gt;create_objects
    IMPORTING
      obj_ref                = obj2.
 
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I Hope it's usefull for you !&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;Marcelo Ramos&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Nov 2007 14:10:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/instance-of-class/m-p/3040363#M719542</guid>
      <dc:creator>marcelo_ramos1</dc:creator>
      <dc:date>2007-11-12T14:10:30Z</dc:date>
    </item>
  </channel>
</rss>

