<?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: Please help me optimize/tune this code for performance in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-tune-this-code-for-performance/m-p/4611573#M1086629</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, you have to make sure that the key being used for the COLLECT is the same as the one used in the READ. But it looks like it should work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The example in the blog has fewer steps and should be quicker.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Don't forget the BINARY SEARCH option on the READ.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 23 Oct 2008 14:12:28 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-10-23T14:12:28Z</dc:date>
    <item>
      <title>Please help me optimize/tune this code for performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-tune-this-code-for-performance/m-p/4611568#M1086624</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;Friends can you please help me optimize code below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is a start routine for SAP BW. &lt;/P&gt;&lt;P&gt;There is one item master table /bic/mzitm_id. Field zitm_id is the primary key of this table and another field is zbib_id.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now in the data_package (source records) in BW start routine for every value of zbib_id I have to determine how many items (zitm_id) exists in table /bic/mzitm_id. (Total no records in table /bic/mzitm_id for a particular value of zbib_id).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Table /bic/zitm_id has about 6million recs and data_package is expected to have on app 300,000 recs (at a time data_package will only 20,000 recs). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the existing code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

 DATA: max_bib_id TYPE /bic/mzitm_id-/bic/zbib_id,
        min_bib_id TYPE /bic/mzitm_id-/bic/zbib_id,
        temp_bib_id TYPE /bic/mzitm_id-/bic/zbib_id,
        tot_lines TYPE i,
        tot_items TYPE i.

  DATA: BEGIN OF lt_zitm_id OCCURS 0,
          zitm_id  TYPE /bic/mzitm_id-/bic/zitm_id,
          zbib_id TYPE /bic/mzitm_id-/bic/zbib_id,
        END OF lt_zitm_id.


  DATA: ls_data_package LIKE LINE OF DATA_PACKAGE[].
  FIELD-SYMBOLS:&amp;lt;ls_data_package&amp;gt; LIKE LINE OF DATA_PACKAGE[].


* ----------------------------------------------------------------

  SORT DATA_PACKAGE BY /bic/zbib_id.

* Find Min BIB ID
  READ TABLE DATA_PACKAGE
        INTO ls_data_package
       INDEX 1.
  min_bib_id = ls_data_package-/bic/zbib_id.

* Find Max BIB ID
  DESCRIBE TABLE DATA_PACKAGE LINES tot_lines.
  READ TABLE DATA_PACKAGE
        INTO ls_data_package
       INDEX tot_lines.
  max_bib_id = ls_data_package-/bic/zbib_id.


* Select Items for BIB range between Min and Max
  SELECT /bic/zitm_id /bic/zbib_id
    FROM /bic/mzitm_id
    INTO TABLE lt_zitm_id
         WHERE /bic/zbib_id BETWEEN min_bib_id
                                AND max_bib_id.


  SORT lt_zitm_id BY zbib_id.
  CLEAR tot_items.
  CLEAR temp_bib_id.

  LOOP AT DATA_PACKAGE ASSIGNING &amp;lt;ls_data_package&amp;gt;.

    IF  &amp;lt;ls_data_package&amp;gt;-/bic/zbib_id = temp_bib_id.
      &amp;lt;ls_data_package&amp;gt;-/bic/ztot_itm = tot_items.

    ELSE.
      CLEAR tot_items.
      LOOP AT lt_zitm_id WHERE zbib_id = &amp;lt;ls_data_package&amp;gt;-/bic/zbib_id.
        tot_items = tot_items + 1.
      ENDLOOP.
      &amp;lt;ls_data_package&amp;gt;-/bic/ztot_itm = tot_items.
      temp_bib_id = &amp;lt;ls_data_package&amp;gt;-/bic/zbib_id.
    ENDIF.

  ENDLOOP.


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Oct 2008 13:45:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-tune-this-code-for-performance/m-p/4611568#M1086624</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-10-23T13:45:17Z</dc:date>
    </item>
    <item>
      <title>Re: Please help me optimize/tune this code for performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-tune-this-code-for-performance/m-p/4611569#M1086625</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If either data_package or zitm_id contain large amounts of data, you should replace the inner nested loop of zitm_id with a binary read followed by a loop using an index and exit.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Oct 2008 13:54:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-tune-this-code-for-performance/m-p/4611569#M1086625</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-10-23T13:54:23Z</dc:date>
    </item>
    <item>
      <title>Re: Please help me optimize/tune this code for performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-tune-this-code-for-performance/m-p/4611570#M1086626</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Rob, thanks for the reply,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you please help me with an example..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am not an ABAP'er, I've been able to write this code with the help from SDN..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Oct 2008 13:56:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-tune-this-code-for-performance/m-p/4611570#M1086626</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-10-23T13:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: Please help me optimize/tune this code for performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-tune-this-code-for-performance/m-p/4611571#M1086627</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Please see:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;[The Performance of Nested Loops|&lt;A class="jive_macro jive_macro_blogpost" href="https://community.sap.com/" __jive_macro_name="blogpost" modifiedtitle="true" __default_attr="41337"&gt;&lt;/A&gt;]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Oct 2008 14:01:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-tune-this-code-for-performance/m-p/4611571#M1086627</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-10-23T14:01:14Z</dc:date>
    </item>
    <item>
      <title>Re: Please help me optimize/tune this code for performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-tune-this-code-for-performance/m-p/4611572#M1086628</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;One more option,&lt;/P&gt;&lt;P&gt;I was thinking to compress the zitm table and then read it in a data_package loop, Is this is a good idea.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the what I am thinking of:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

  DATA: BEGIN OF lt_zitm_id_2 OCCURS 0,
               zbib_id TYPE /bic/mzitm_id-/bic/zbib_id,
		zcount type i,
        END OF lt_zitm_id_2.


loop at lt_zitm_id
clear lt_zitm_id_2.
lt_zitm_id_2-zbib_id = lt_zitm_id-zbib_id.
lt_zitm_id_2-zcount = 1.
collect lt_zitm_id_2.

endloop.

sort lt_zitm_id_2 by zbib_id.

Now loop at data_package and read lt_zitm_id with key zbib_id....

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Oct 2008 14:06:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-tune-this-code-for-performance/m-p/4611572#M1086628</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-10-23T14:06:11Z</dc:date>
    </item>
    <item>
      <title>Re: Please help me optimize/tune this code for performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-tune-this-code-for-performance/m-p/4611573#M1086629</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, you have to make sure that the key being used for the COLLECT is the same as the one used in the READ. But it looks like it should work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The example in the blog has fewer steps and should be quicker.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Don't forget the BINARY SEARCH option on the READ.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Oct 2008 14:12:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-tune-this-code-for-performance/m-p/4611573#M1086629</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-10-23T14:12:28Z</dc:date>
    </item>
    <item>
      <title>Re: Please help me optimize/tune this code for performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-tune-this-code-for-performance/m-p/4611574#M1086630</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Rob, here is the modified code. Can you please give some recommendations on it&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

  DATA: max_bib_id TYPE /bic/mzitm_id-/bic/zbib_id,
        min_bib_id TYPE /bic/mzitm_id-/bic/zbib_id,
        temp_bib_id TYPE /bic/mzitm_id-/bic/zbib_id,
        tot_lines TYPE i,
        tot_items TYPE i.

  DATA: BEGIN OF lt_zitm_id OCCURS 0,
          zitm_id  TYPE /bic/mzitm_id-/bic/zitm_id,
          zbib_id TYPE /bic/mzitm_id-/bic/zbib_id,
        END OF lt_zitm_id.

  DATA: BEGIN OF lt_zitm_id_2 OCCURS 0,
          zbib_id TYPE /bic/mzitm_id-/bic/zbib_id,
          zcount TYPE i,
        END OF lt_zitm_id_2.

  DATA: ls_zitm_id_2 LIKE LINE OF lt_zitm_id_2[].

  DATA: ls_data_package LIKE LINE OF data_package[].
  FIELD-SYMBOLS:&amp;lt;ls_data_package&amp;gt; LIKE LINE OF data_package[].


* ----------------------------------------------------------------

  SORT data_package BY /bic/zbib_id.

* Find Min BIB ID
  READ TABLE data_package
        INTO ls_data_package
       INDEX 1.
  min_bib_id = ls_data_package-/bic/zbib_id.

* Find Max BIB ID
  DESCRIBE TABLE data_package LINES tot_lines.
  READ TABLE data_package
        INTO ls_data_package
       INDEX tot_lines.
  max_bib_id = ls_data_package-/bic/zbib_id.


* Select Items for BIB range between Min and Max
  SELECT /bic/zitm_id /bic/zbib_id
    FROM /bic/mzitm_id
    INTO TABLE lt_zitm_id
         WHERE /bic/zbib_id BETWEEN min_bib_id
                                AND max_bib_id.


  SORT lt_zitm_id BY zbib_id.

  LOOP AT lt_zitm_id.
    CLEAR lt_zitm_id_2.
    lt_zitm_id_2-zbib_id = lt_zitm_id-zbib_id.
    lt_zitm_id_2-zcount = 1.
    COLLECT lt_zitm_id_2.
  ENDLOOP.


  CLEAR tot_items.
  CLEAR temp_bib_id.
  SORT lt_zitm_id_2 BY zbib_id.

  LOOP AT data_package ASSIGNING &amp;lt;ls_data_package&amp;gt;.

    IF  &amp;lt;ls_data_package&amp;gt;-/bic/zbib_id = temp_bib_id.
      &amp;lt;ls_data_package&amp;gt;-/bic/ztot_itm = tot_items.

    ELSE.
      CLEAR tot_items.

      READ TABLE lt_zitm_id_2
            INTO ls_zitm_id_2
          WITH KEY zbib_id = &amp;lt;ls_data_package&amp;gt;-/bic/zbib_id
            BINARY SEARCH.

      IF sy-subrc EQ 0.
        &amp;lt;ls_data_package&amp;gt;-/bic/ztot_itm = ls_zitm_id_2-zcount.
        temp_bib_id = &amp;lt;ls_data_package&amp;gt;-/bic/zbib_id.
      ENDIF.
    ENDIF.

  ENDLOOP.


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Oct 2008 14:23:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-tune-this-code-for-performance/m-p/4611574#M1086630</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-10-23T14:23:25Z</dc:date>
    </item>
    <item>
      <title>Re: Please help me optimize/tune this code for performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-tune-this-code-for-performance/m-p/4611575#M1086631</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It looks OK to me - why not just give it a try?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Oct 2008 14:27:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-tune-this-code-for-performance/m-p/4611575#M1086631</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-10-23T14:27:43Z</dc:date>
    </item>
    <item>
      <title>Re: Please help me optimize/tune this code for performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-tune-this-code-for-performance/m-p/4611576#M1086632</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Rob I've been able to get a reduction in run time from app 2hours down to 15 mins.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there anything else you can recommend for further optimization in this code.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Oct 2008 14:49:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-tune-this-code-for-performance/m-p/4611576#M1086632</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-10-23T14:49:34Z</dc:date>
    </item>
    <item>
      <title>Re: Please help me optimize/tune this code for performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-tune-this-code-for-performance/m-p/4611577#M1086633</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt; Rob I've been able to get a reduction in run time from app 2hours down to 15 mins.&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; Is there anything else you can recommend for further optimization in this code.&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Well, OK - at least that's something. The only other thing I can think of is to do it as I suggested above. That will get rid of the COLLECT step.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is what I mean - but check please:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA: tab_index TYPE sy-tabix.

LOOP AT data_package ASSIGNING &amp;lt;ls_data_package&amp;gt;.

  IF  &amp;lt;ls_data_package&amp;gt;-/bic/zbib_id = temp_bib_id.
    &amp;lt;ls_data_package&amp;gt;-/bic/ztot_itm = tot_items.

  ELSE.
    CLEAR tot_items.

    READ TABLE lt_zitm_id WITH KEY
      zbib_id = &amp;lt;ls_data_package&amp;gt;-/bic/zbib_id
      BINARY SEARCH.

    IF sy-subrc = 0.
      tab_index = sy-tabix.

      LOOP AT lt_zitm_id FROM tab_index.
        IF lt_zitm_id-zbib_id &amp;lt;&amp;gt; &amp;lt;ls_data_package&amp;gt;-/bic/zbib_id.
          EXIT.
        ENDIF.

        tot_items = tot_items + 1.
        &amp;lt;ls_data_package&amp;gt;-/bic/ztot_itm = tot_items.
        temp_bib_id = &amp;lt;ls_data_package&amp;gt;-/bic/zbib_id.

      ENDLOOP.
    ENDIF.

  ENDIF.

ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Another thing - make sure that the results are the same as before.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Rob Burbank on Oct 23, 2008 11:37 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Oct 2008 14:57:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-tune-this-code-for-performance/m-p/4611577#M1086633</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-10-23T14:57:34Z</dc:date>
    </item>
  </channel>
</rss>

