<?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 Improving persistent class performance with on-demand DB reads? in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/improving-persistent-class-performance-with-on-demand-db-reads/m-p/6068272#M1355143</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;Something that has been troubling me for some time is the data access design of persistent classes. A persistent class loads the ENTIRE data set when it is instantiated. &lt;/P&gt;&lt;P&gt;To me this defeats one of the advantages of get/set methods. What I would like is to be able to read data when it is first accessed. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example: A purchase order header can be loaded in a few ms. However with items it can take 10 times as long - even more if the items are implemented as persistent classes themselves. If items are only needed half the time, a significant performance gain is realized by only reading items the first time the GET_ITEMS method is called. In my own persistence implementations using BI_PERSISTENT (Nothing to do with ABAP Persistent Classes), I implement this using private attributes to buffer data, along the lines of:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;method get_items. 
  if m_items[] is initial. 
    m_items = &amp;lt;read and/or instantiate items&amp;gt;. 
  endif.
  re_items = m_items.
endif.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using ABAP Persistent Objects this does not appear to be possible since they insist on loading everything up front in the DB mapping or IF_OS_STATE~INIT methods. Is some kind of on-demand reading possible using ABAP Persistent Classes?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any input appreciated&lt;/P&gt;&lt;P&gt;Cheers, &lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 05 Sep 2009 11:58:09 GMT</pubDate>
    <dc:creator>pokrakam</dc:creator>
    <dc:date>2009-09-05T11:58:09Z</dc:date>
    <item>
      <title>Improving persistent class performance with on-demand DB reads?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/improving-persistent-class-performance-with-on-demand-db-reads/m-p/6068272#M1355143</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;Something that has been troubling me for some time is the data access design of persistent classes. A persistent class loads the ENTIRE data set when it is instantiated. &lt;/P&gt;&lt;P&gt;To me this defeats one of the advantages of get/set methods. What I would like is to be able to read data when it is first accessed. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example: A purchase order header can be loaded in a few ms. However with items it can take 10 times as long - even more if the items are implemented as persistent classes themselves. If items are only needed half the time, a significant performance gain is realized by only reading items the first time the GET_ITEMS method is called. In my own persistence implementations using BI_PERSISTENT (Nothing to do with ABAP Persistent Classes), I implement this using private attributes to buffer data, along the lines of:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;method get_items. 
  if m_items[] is initial. 
    m_items = &amp;lt;read and/or instantiate items&amp;gt;. 
  endif.
  re_items = m_items.
endif.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using ABAP Persistent Objects this does not appear to be possible since they insist on loading everything up front in the DB mapping or IF_OS_STATE~INIT methods. Is some kind of on-demand reading possible using ABAP Persistent Classes?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any input appreciated&lt;/P&gt;&lt;P&gt;Cheers, &lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 05 Sep 2009 11:58:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/improving-persistent-class-performance-with-on-demand-db-reads/m-p/6068272#M1355143</guid>
      <dc:creator>pokrakam</dc:creator>
      <dc:date>2009-09-05T11:58:09Z</dc:date>
    </item>
    <item>
      <title>Re: Improving persistent class performance with on-demand DB reads?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/improving-persistent-class-performance-with-on-demand-db-reads/m-p/6068273#M1355144</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Closed thread due to lack of interest. &lt;/P&gt;&lt;P&gt;I still haven't gotten around the issue so will happily reopen if anyone has any input as I am still interested in the topic.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Apr 2010 11:54:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/improving-persistent-class-performance-with-on-demand-db-reads/m-p/6068273#M1355144</guid>
      <dc:creator>pokrakam</dc:creator>
      <dc:date>2010-04-15T11:54:58Z</dc:date>
    </item>
    <item>
      <title>Re: Improving persistent class performance with on-demand DB reads?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/improving-persistent-class-performance-with-on-demand-db-reads/m-p/6068274#M1355145</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mike,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;yes, I am also very interested in this topic. While developing my first (and only a mid-complex) persistence application, I am expecting slightly different behaviour of linked persistent objects than you described above. According to the book 'Object Services in ABAP' and lazy loading paradigm mentioned there, the referenced persistent objects should be instantiated as &lt;EM&gt;representative objects&lt;/EM&gt; only, containing no data, and the data should be physically loaded from database only once it's really needed (ie. accessed or explicitly instantiated). This should be the approach preventing the situation of mass chained instantiation of many linked persistent objects where most of them will not be needed, probably.&lt;/P&gt;&lt;P&gt;This is what they say about instantiation of persistent objects that are linked by persistent references. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, since the persistent objects do not allow creating of 1:N relationships (classics: HEADER-&amp;gt;ITEMS) via persistent references automatically, then this kind of relationship has to be maintained manually and therefore I expect you having full control of when it is accessed and instantiated for the first time...? What I want to ask here is then: is there any suitable approach which allows to maintain 1:N relationship fully or semi-automatically and which (as a disadvantage) makes the problem for you with 'full' instantiation? Am I missing something? There are also some threads &lt;SPAN __jive_macro_name="thread" id="132057"&gt;&lt;/SPAN&gt;  regarding persistent mapping of table-like attributes, but no relevant answers (this should solve my problem as the table of persistent references could be saved then).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Until now, I have found almost nothing about how the 1:N relationship should be correctly built (only 1:1 or M:1 is supported via persistent references), so I am applying the following approach in my app. Any comments are welcome (excuse some typos, as this is written in Notepad, not on the running system):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; 
ref_header = zca_header=&amp;gt;agent-&amp;gt;create_persistent( ).
guid_of_header_class = ref_header-&amp;gt;get_cl_guid( )."cl_guid is set in IF_OS_STATE~INIT
guid_of_header_instance = 
  zca_header=&amp;gt;agent-&amp;gt;if_os_ca_service~get_oid_by_ref( ref_header ).
ref_header-&amp;gt;set_inst_guid(                   "keep header inst. ref. for future lookups 
i_inst_guid = guid_of_header_instance 
).             
lt_r_items = ref_header-&amp;gt;create_items(       "lt_r_items = table of items references
  i_cl_guid = guid_of_header_class
  i_inst_guid = guid_of_header_instance
  it_items = lt_items )
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and the method zcl_header-&amp;gt;create_items then looks somewhat like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; 
loop at it_items assigning &amp;lt;it_items&amp;gt;.
  ref_item = zca_item=&amp;gt;agent-&amp;gt;create_persistent( ).
  ref_item-&amp;gt;set_cl_guid( i_header_cl_guid = i_cl_guid ).
  ref_item-&amp;gt;set_inst_guid( i_header_inst_guid = i_inst_guid ).
  ref_item-&amp;gt;set_some_other_attrib( 
    i_some_other_attrib = &amp;lt;it_items&amp;gt;-some_other_attrib 
    ).
  append ref_item to rt_r_items.             "rt_r_items = table of items references
endloop.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have created a secondary index on items for header_cl_guid and header_inst_guid. This is used during the re-load of already saved items for particular header entry. Query service is used with header_cl_guid and header_inst_guid of actual header entry as filter criteria for item pesistent objects and table of item references is returned. Thus the instance attribute lt_r_items of ref_header is filled with references to relevant items again.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;Michal&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 01 Oct 2011 23:52:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/improving-persistent-class-performance-with-on-demand-db-reads/m-p/6068274#M1355145</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-10-01T23:52:20Z</dc:date>
    </item>
  </channel>
</rss>

