<?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: Creating object class dynamically in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/creating-object-class-dynamically/m-p/1478490#M224170</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Swatantra&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The number of entries in your itab is not relevant. The question is: What does "dynamically" mean?&lt;/P&gt;&lt;P&gt;Does it mean that you have to create instances of different classes depending on the values in your itab entry? Or are all instances you want to create of the same class?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the first case you obviously have to define IF conditions or CASE/ENDCASE and then call the constructor of the appropriate class. You could store these different instances in an itab whose lines are of &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPE REF TO object.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the latter case you can store the instances in an itab whose lines are of &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPE REF TO &amp;lt;specific class&amp;gt;.&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>Tue, 22 Aug 2006 14:50:20 GMT</pubDate>
    <dc:creator>uwe_schieferstein</dc:creator>
    <dc:date>2006-08-22T14:50:20Z</dc:date>
    <item>
      <title>Creating object class dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/creating-object-class-dynamically/m-p/1478488#M224168</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;I need to create object dynamically for a class.eg when i loop thru internal table i need to create an object per pass of the loop and no of entries  in itab can be known at runtime only &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any clues&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Swatantra&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Aug 2006 14:41:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/creating-object-class-dynamically/m-p/1478488#M224168</guid>
      <dc:creator>swatantra_vijay3</dc:creator>
      <dc:date>2006-08-22T14:41:58Z</dc:date>
    </item>
    <item>
      <title>Re: Creating object class dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/creating-object-class-dynamically/m-p/1478489#M224169</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Check this sample program, where it is creating a number of objects and appending them to a object list.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

report zrich_0001.

types: begin of telements,
       element(30) type c,
       value(30) type c,
       end of telements.

*---------------------------------------------------------------------*
*       CLASS lcl_element DEFINITION
*---------------------------------------------------------------------*
class lcl_element definition.

  public section.

    data: ielements type table of telements,
          xelements type telements.

    methods: constructor importing im_elements type telements,
             write_out.

endclass.

*---------------------------------------------------------------------*
*       CLASS lcl_element IMPLEMENTATION
*---------------------------------------------------------------------*
class lcl_element implementation.

  method constructor.

    append im_elements to ielements.

  endmethod.

  method write_out.
    loop at ielements into xelements.
      write:/ xelements-element, xelements-value.
    endloop.

  endmethod.

endclass.


data: itab type table of telements with header line.

data: r_element type ref to lcl_element.
data: r_elementlist type table of ref to lcl_element.

start-of-selection.

* Create the initial list of elements.
  itab-element = 'ELEMENTA'.
  itab-value   = 'Val_A'.
  append itab.

  itab-element = 'ELEMENTB'.
  itab-value   = 'Val_B'.
  append itab.

  itab-element = 'ELEMENTC'.
  itab-value   = 'Val_C'.
  append itab.

* Create instances of the element object
* and add to the list
  loop at itab .

    create object r_element
        exporting
             im_elements = itab.
    append r_element to r_elementlist.

  endloop.

* loop at the list and write out the element objects.
* Notice that the r_elementlist is an internal table
* which contains 3 objects.  Those three objects each
* contain 1 internal table with one record each.
  loop at r_elementlist into r_element.
    call method r_element-&amp;gt;write_out.
  endloop.

&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>Tue, 22 Aug 2006 14:46:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/creating-object-class-dynamically/m-p/1478489#M224169</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2006-08-22T14:46:24Z</dc:date>
    </item>
    <item>
      <title>Re: Creating object class dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/creating-object-class-dynamically/m-p/1478490#M224170</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Swatantra&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The number of entries in your itab is not relevant. The question is: What does "dynamically" mean?&lt;/P&gt;&lt;P&gt;Does it mean that you have to create instances of different classes depending on the values in your itab entry? Or are all instances you want to create of the same class?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the first case you obviously have to define IF conditions or CASE/ENDCASE and then call the constructor of the appropriate class. You could store these different instances in an itab whose lines are of &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPE REF TO object.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the latter case you can store the instances in an itab whose lines are of &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPE REF TO &amp;lt;specific class&amp;gt;.&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>Tue, 22 Aug 2006 14:50:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/creating-object-class-dynamically/m-p/1478490#M224170</guid>
      <dc:creator>uwe_schieferstein</dc:creator>
      <dc:date>2006-08-22T14:50:20Z</dc:date>
    </item>
  </channel>
</rss>

