<?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: ABAP OO, Creating object dynamically in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oo-creating-object-dynamically/m-p/878650#M51226</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;Its not all that difficult in ABAP as well. The following code is based on Chapter 5, Listing 5.20 from book ABAP Objects. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What you need is an internal table of type &amp;lt;your sales object&amp;gt; e.g.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
DATA: BEGIN OF obj_sales_order
        sales_order_no LIKE &amp;lt;sales_order_no_type&amp;gt;,
        &amp;lt;...&amp;gt;,
        objref TYPE REF TO &amp;lt;SALES_ORDER_CLASS&amp;gt;
      END OF obj_sales_order,
      
      reftab LIKE SORTED TABLES OF obj_sales_order
                  WITH UNIQUE KEY sales_order_no 
                                  &amp;lt;other key attributes&amp;gt;.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now all you need to do is to do a SELECT...ENDSELECT loop, and:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
SELECT ...
obj_sales_order-sales_order_no = &amp;lt;selection result&amp;gt;
obj_sales_order-&amp;lt;other key attr&amp;gt; = &amp;lt;selection result&amp;gt;

READ TABLE reftab INTO obj_sales_order
                  FROM obj_sales_order.

IF sy-subrc &amp;lt;&amp;gt; 0.
  CREATE OBJECT obj_sales_order-objref
         EXPORTING ...
         EXCEPTIONS ...
  IF sy-subrc &amp;lt;&amp;gt; 0.
    MESSAGE ...
    CONTINUE.
  ELSE.
    INSERT obj_sales_order INTO TABLE reftab.
  ENDIF.
ENDIF.
CALL METHOD obj_sales_order-objref-&amp;gt;&amp;lt;method&amp;gt;.
ENDSELECT.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 06 Jan 2005 11:57:44 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2005-01-06T11:57:44Z</dc:date>
    <item>
      <title>ABAP OO, Creating object dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oo-creating-object-dynamically/m-p/878646#M51222</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everybody,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;     I&amp;#146;m currently working on some Abap OO examples. Everything is working ok except for the following: Creating objects dynamically.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is what I&amp;#146;d like to do:&lt;/P&gt;&lt;P&gt;Lets say we obtain a bunch of sales orders using a simple select statement and place them in an internal table. For each entry in our internal table, I&amp;#146;d like to generate a new sales order object. This salesorder object is a simple class with a constructor with an Id and some other attributes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When this is done, I&amp;#146;d like to append every object to a new object, say basket, so that this basket contains something like an internal table within each record a reference to the salesorder. Is this easy to do? I&amp;#146;m using the example that is described in the sap guide (create object pointer type (class_name) but it looks to me that you still have to declare the reference variables before you can create the object. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hmm, I think Java is better suited for a job like this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope you can help,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers and Best wishes&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Laurens Steffers&lt;/P&gt;&lt;P&gt;The Netherlands.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Jan 2005 11:14:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oo-creating-object-dynamically/m-p/878646#M51222</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-01-06T11:14:32Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP OO, Creating object dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oo-creating-object-dynamically/m-p/878647#M51223</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you are working on WAS 6.4, then this link would be very useful for you:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/a1-8-4/advanced" target="test_blank"&gt;https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/a1-8-4/advanced&lt;/A&gt; and generic programming in abap.pdf&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;P&gt;&lt;/P&gt;&lt;P&gt;P.S. - This question has been asked previously as well&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Jan 2005 11:24:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oo-creating-object-dynamically/m-p/878647#M51223</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-01-06T11:24:49Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP OO, Creating object dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oo-creating-object-dynamically/m-p/878648#M51224</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Subramanian,&lt;/P&gt;&lt;P&gt;   thank you for the link. Funny thing is that, with the example of dynamic tokens, I didn't use the uppercase in the following statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  CALL METHOD: field-&amp;gt;create_object  EXPORTING class_name = 'airplane'&lt;/P&gt;&lt;P&gt;                                  IMPORTING pointer = r .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Changing it to AIRPLANE, the creation went ok. I think I'll go from here using the whitepaper you've sent me. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was not aware of the previous posting. I did a search but looking at all the 1400 messages... &lt;SPAN __jive_emoticon_name="wink"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;&lt;P&gt;Laurens&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Jan 2005 11:41:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oo-creating-object-dynamically/m-p/878648#M51224</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-01-06T11:41:33Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP OO, Creating object dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oo-creating-object-dynamically/m-p/878649#M51225</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, &lt;/P&gt;&lt;P&gt;Below is a sample code. You may create an internal table for your object and append the objects for salesorders to it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data:&lt;/P&gt;&lt;P&gt; begin of itabobjects,&lt;/P&gt;&lt;P&gt;   salesorder type ref to cl_sales_order,&lt;/P&gt;&lt;P&gt; end of itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itabsales.&lt;/P&gt;&lt;P&gt;   create object itabobjects-salesorder &lt;/P&gt;&lt;P&gt;     importing vbeln = itabsales-vbeln.&lt;/P&gt;&lt;P&gt;   append itabobjects.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="--------------------------------------" /&gt;&lt;P&gt;Please, give points if it helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Jan 2005 11:43:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oo-creating-object-dynamically/m-p/878649#M51225</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-01-06T11:43:50Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP OO, Creating object dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oo-creating-object-dynamically/m-p/878650#M51226</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;Its not all that difficult in ABAP as well. The following code is based on Chapter 5, Listing 5.20 from book ABAP Objects. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What you need is an internal table of type &amp;lt;your sales object&amp;gt; e.g.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
DATA: BEGIN OF obj_sales_order
        sales_order_no LIKE &amp;lt;sales_order_no_type&amp;gt;,
        &amp;lt;...&amp;gt;,
        objref TYPE REF TO &amp;lt;SALES_ORDER_CLASS&amp;gt;
      END OF obj_sales_order,
      
      reftab LIKE SORTED TABLES OF obj_sales_order
                  WITH UNIQUE KEY sales_order_no 
                                  &amp;lt;other key attributes&amp;gt;.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now all you need to do is to do a SELECT...ENDSELECT loop, and:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
SELECT ...
obj_sales_order-sales_order_no = &amp;lt;selection result&amp;gt;
obj_sales_order-&amp;lt;other key attr&amp;gt; = &amp;lt;selection result&amp;gt;

READ TABLE reftab INTO obj_sales_order
                  FROM obj_sales_order.

IF sy-subrc &amp;lt;&amp;gt; 0.
  CREATE OBJECT obj_sales_order-objref
         EXPORTING ...
         EXCEPTIONS ...
  IF sy-subrc &amp;lt;&amp;gt; 0.
    MESSAGE ...
    CONTINUE.
  ELSE.
    INSERT obj_sales_order INTO TABLE reftab.
  ENDIF.
ENDIF.
CALL METHOD obj_sales_order-objref-&amp;gt;&amp;lt;method&amp;gt;.
ENDSELECT.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Jan 2005 11:57:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oo-creating-object-dynamically/m-p/878650#M51226</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-01-06T11:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP OO, Creating object dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oo-creating-object-dynamically/m-p/878651#M51227</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Example worked perfectly (when adjusted to my needs of course &lt;SPAN __jive_emoticon_name="wink"&gt;&lt;/SPAN&gt; )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers and thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Laurens&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Jan 2005 13:05:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oo-creating-object-dynamically/m-p/878651#M51227</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-01-06T13:05:04Z</dc:date>
    </item>
  </channel>
</rss>

