<?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: perfomance optimization code - Select Statement in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/perfomance-optimization-code-select-statement/m-p/7032456#M1499577</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1. Avoid select statement inside loop. It will hit the database multiple times, which is time consuming. Select all the cost entries from DSO_TABLE for RESULT_PACKAGE using FOR ALL ENTRIES. Then, inside the loop read the cost using READ with BINARY SEARCH after sorting the table outside the loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. What is the size of  RESULT_PACKAGE? If it's a huge table then use field symbols instead of MODIFY statement. It's faster.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

Data rp TYPE _ty_s_TG_1.

field-symbols: &amp;lt;fs_rp&amp;gt; LIKE LINE OF RESULT_PACKAGE.

"Declare one internal table int_cost with item and cost

SELECT ITEM
             COST 
   FROM DSO_TABLE 
     INTO int_cost
       FOR ALL ENTRIES IN RESULT_PACKAGE
        WHERE ITEMID EQ RESULT_PACKAGE-ITEMID.

IF sy-subrc EQ 0.
  SORT int_cost BY itemid.
ENDIF.


LOOP AT RESULT_PACKAGE ASSIGNING &amp;lt;fs_rp&amp;gt;.

  READ TABLE int_cost INTO wa_cost WITH key itemid = &amp;lt;fs_rp&amp;gt;-itemid
                                                                       binary search.

  If sy-subrc EQ 0.
   &amp;lt;fs_rp&amp;gt;-cost = wa_cost-cost.
  ENDIF.

ENDLOOP.




&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Satyajit on May 27, 2010 11:45 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 27 May 2010 06:12:59 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2010-05-27T06:12:59Z</dc:date>
    <item>
      <title>perfomance optimization code - Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/perfomance-optimization-code-select-statement/m-p/7032453#M1499574</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;I wrote a piece of code that is working well but my boss wants me to rewrite the code due to performance since we are going to process huge amount of data using READ KEY and Internal table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Data rp TYPE _ty_s_TG_1.
LOOP AT RESULT_PACKAGE INTO rp.
  SELECT SINGLE COST FROM DSO_TABLE  INTO rp-COST
        WHERE ITEMID EQ rp-ITEMID.
        MODIFY RESULT_PACKAGE FROM rp.

  Clear rp.

ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do I rewrite this code for better performance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Matt on May 27, 2010 8:23 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 May 2010 05:55:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/perfomance-optimization-code-select-statement/m-p/7032453#M1499574</guid>
      <dc:creator>bhat_vaidya2</dc:creator>
      <dc:date>2010-05-27T05:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: perfomance optimization code - Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/perfomance-optimization-code-select-statement/m-p/7032454#M1499575</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;Instead of giving select statement inside the loop try using it Outside the loop.&lt;/P&gt;&lt;P&gt;SELECT  records from the database table which are relevant (Using FOR ALL ENTRIES).&lt;/P&gt;&lt;P&gt;SORT the internal table&lt;/P&gt;&lt;P&gt;Use a READ TABLE statement WITH BINARY SEARCH addition inside the loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Lakshman.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 May 2010 06:01:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/perfomance-optimization-code-select-statement/m-p/7032454#M1499575</guid>
      <dc:creator>former_member209217</dc:creator>
      <dc:date>2010-05-27T06:01:16Z</dc:date>
    </item>
    <item>
      <title>Re: perfomance optimization code - Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/perfomance-optimization-code-select-statement/m-p/7032455#M1499576</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;Try the below code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; Data rp TYPE &lt;U&gt;ty&lt;/U&gt;s_TG_1.&lt;/P&gt;&lt;P&gt; data : begin of itab1,&lt;/P&gt;&lt;P&gt;            include structure &amp;lt;DSO_TABLE&amp;gt;,&lt;/P&gt;&lt;P&gt;data : end of itab1.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;    SELECT costr ITEMID &lt;/P&gt;&lt;P&gt;      FROM DSO_TABLE&lt;/P&gt;&lt;P&gt;      INTO TABLE itab1&lt;/P&gt;&lt;P&gt;       FOR ALL ENTRIES IN RESULT_PACKAGE&lt;/P&gt;&lt;P&gt;     WHERE &amp;lt;Conditon&amp;gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; LOOP AT RESULT_PACKAGE INTO rp.&lt;/P&gt;&lt;P&gt; read table itab1 with key itemid = rp-item.&lt;/P&gt;&lt;P&gt;  MODIFY RESULT_PACKAGE. &lt;/P&gt;&lt;P&gt; ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Nehruu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 May 2010 06:10:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/perfomance-optimization-code-select-statement/m-p/7032455#M1499576</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-05-27T06:10:41Z</dc:date>
    </item>
    <item>
      <title>Re: perfomance optimization code - Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/perfomance-optimization-code-select-statement/m-p/7032456#M1499577</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1. Avoid select statement inside loop. It will hit the database multiple times, which is time consuming. Select all the cost entries from DSO_TABLE for RESULT_PACKAGE using FOR ALL ENTRIES. Then, inside the loop read the cost using READ with BINARY SEARCH after sorting the table outside the loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. What is the size of  RESULT_PACKAGE? If it's a huge table then use field symbols instead of MODIFY statement. It's faster.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

Data rp TYPE _ty_s_TG_1.

field-symbols: &amp;lt;fs_rp&amp;gt; LIKE LINE OF RESULT_PACKAGE.

"Declare one internal table int_cost with item and cost

SELECT ITEM
             COST 
   FROM DSO_TABLE 
     INTO int_cost
       FOR ALL ENTRIES IN RESULT_PACKAGE
        WHERE ITEMID EQ RESULT_PACKAGE-ITEMID.

IF sy-subrc EQ 0.
  SORT int_cost BY itemid.
ENDIF.


LOOP AT RESULT_PACKAGE ASSIGNING &amp;lt;fs_rp&amp;gt;.

  READ TABLE int_cost INTO wa_cost WITH key itemid = &amp;lt;fs_rp&amp;gt;-itemid
                                                                       binary search.

  If sy-subrc EQ 0.
   &amp;lt;fs_rp&amp;gt;-cost = wa_cost-cost.
  ENDIF.

ENDLOOP.




&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Satyajit on May 27, 2010 11:45 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 May 2010 06:12:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/perfomance-optimization-code-select-statement/m-p/7032456#M1499577</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-05-27T06:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: perfomance optimization code - Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/perfomance-optimization-code-select-statement/m-p/7032457#M1499578</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; 1. Avoid select statement inside loop. It will hit the database multiple times, which is time consuming. Select all the cost entries from DSO_TABLE for RESULT_PACKAGE using FOR ALL ENTRIES. Then, inside the loop read the cost using READ with BINARY SEARCH after sorting the table outside the loop.&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; 2. What is the size of  RESULT_PACKAGE? If it's a huge table then use field symbols instead of MODIFY statement. It's faster.&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;/CODE&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;CODE&gt;
&amp;gt; 
&amp;gt; Data rp TYPE _ty_s_TG_1.
&amp;gt; 
&amp;gt; field-symbols: &amp;lt;fs_rp&amp;gt; LIKE LINE OF RESULT_PACKAGE.
&amp;gt; 
&amp;gt; "Declare one internal table int_cost with item and cost
&amp;gt; 
&amp;gt; SELECT ITEM
&amp;gt;              COST 
&amp;gt;    FROM DSO_TABLE 
&amp;gt;      INTO int_cost
&amp;gt;        FOR ALL ENTRIES IN RESULT_PACKAGE
&amp;gt;         WHERE ITEMID EQ RESULT_PACKAGE-ITEMID.
&amp;gt; 
&amp;gt; IF sy-subrc EQ 0.
&amp;gt;   SORT int_cost BY itemid.
&amp;gt; ENDIF.
&amp;gt; 
&amp;gt; 
&amp;gt; LOOP AT RESULT_PACKAGE ASSIGNING &amp;lt;fs_rp&amp;gt;.
&amp;gt; 
&amp;gt;   READ TABLE int_cost INTO wa_cost WITH key itemid = &amp;lt;fs_rp&amp;gt;-itemid
&amp;gt;                                                                        binary search.
&amp;gt; 
&amp;gt;   If sy-subrc EQ 0.
&amp;gt;    &amp;lt;fs_rp&amp;gt;-cost = wa_cost-cost.
&amp;gt;   ENDIF.
&amp;gt; 
&amp;gt; ENDLOOP.
&amp;gt; 
&amp;gt; 
&amp;gt; 
&amp;gt; 
&amp;gt; &lt;/CODE&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; Edited by: Satyajit on May 27, 2010 11:45 AM&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use the above solution, but define int_cost as a HASHED table with UNIQUE KEY ITEMID, and use READ TABLE int_cost INTO wa_cost WITH TABLE KEY itemid = &amp;lt;fs_rp&amp;gt;-itemid.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I'm astonished that people are still using BINARY SEARCH. Please read the help on SORTED and HASHED tables, and start using them in your programs!&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 May 2010 06:27:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/perfomance-optimization-code-select-statement/m-p/7032457#M1499578</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2010-05-27T06:27:04Z</dc:date>
    </item>
    <item>
      <title>Re: perfomance optimization code - Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/perfomance-optimization-code-select-statement/m-p/7032458#M1499579</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Everything right what MATT said.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Two additional comments:&lt;/P&gt;&lt;P&gt;+ What does the huge table RESULT_PACKAGE come from? Maybe it is also selected .... then a Join could even be better.&lt;/P&gt;&lt;P&gt;+ And always check whether the table in the SELECT statement is table buffered, if so then leave it inside the loop! Remove SELECT from LOOPs is incorrect, you must remove DB accesses, but not table buffer accesses!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 May 2010 07:44:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/perfomance-optimization-code-select-statement/m-p/7032458#M1499579</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-05-27T07:44:53Z</dc:date>
    </item>
    <item>
      <title>Re: perfomance optimization code - Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/perfomance-optimization-code-select-statement/m-p/7032459#M1499580</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Seigfried - if you see "RESULT_PACKAGE", "SOURCE_PACKAGE", "DATA_PACKAGE", then that implies that the ABAP is within an expert, start or end routine in a BW transformation/update routine. The volume of data will typically be between a few tens of thousands of records, to a few hundred thousand, being processed at one time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;matt&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 May 2010 08:24:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/perfomance-optimization-code-select-statement/m-p/7032459#M1499580</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2010-05-27T08:24:37Z</dc:date>
    </item>
    <item>
      <title>Re: perfomance optimization code - Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/perfomance-optimization-code-select-statement/m-p/7032460#M1499581</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 think your logic having identical read problem,  It can avoid using following way&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;types: begin of ty_DSO_TABLE,
            itemid type DSO_TABLE-itemid,
            cost   type dso_table-cost,
            exist  type c,
           end of type ty_DSO_TABLE.
DATA: it_DSO_TABLE type hashed table of ty_DSO_TABLE with unique key itemid,
     wa_DSO_TABLE type ty_DSO_TABLE.
Fields-symbols:  &amp;lt;rp&amp;gt; TYPE _ty_s_TG_1.

LOOP AT RESULT_PACKAGE assigning &amp;lt;rp&amp;gt;.
  clear wa_DSO_TABLE .
  Read table IT_DSO_TABLE into wa_DSO_TABLE with table key itemid = &amp;lt;rp&amp;gt;-ITEMID.
  if sy-subrc ne 0.
      select single itemid cost into wa_DSO_TABLE from DSO_TABLE client specified
         where mandt = sy-mandt
              and itemid =  &amp;lt;rp&amp;gt;-ITEMID.
     if sy-subrc eq 0.
          wa_dso_table-exist = 'X'
     else.
         wa_dso_table-itemid.
     endif.
     insert wa_dso_table into table IT_DSO_TABLE .
 endif
if wa_dso_table-exist = 'X'.
&amp;lt;rp&amp;gt;-cost = wa_DSO_TABLE-cost. 
endif.
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Otherwise you can you satyajit logic for master data which does not have identical read and small noumber of records&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rgds&lt;/P&gt;&lt;P&gt;Ravi Lanjewar&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Matt on May 27, 2010 12:48 PM - add  tags&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 May 2010 10:30:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/perfomance-optimization-code-select-statement/m-p/7032460#M1499581</guid>
      <dc:creator>ravi_lanjewar</dc:creator>
      <dc:date>2010-05-27T10:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: perfomance optimization code - Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/perfomance-optimization-code-select-statement/m-p/7032461#M1499582</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;oh, still not finished ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;@Matt, thanks I rarely encountr BW, but now I understand the huge amount of data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The last comment makes then also sense, however it is not the optimal solution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The optimal solution is a combination of all recommendations. The FOR ALL ENTRIES will be extremely slow if there are many duplicates in the driver table. The last recommendation will still do a lot of SELECT SINGLE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If itemid is not a numerical field&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
LOOP AT RESULT_PACKAGE ASSIGNING &amp;lt;fs_rp&amp;gt;.
  COLLECT &amp;lt;fs_rp-item into itab.
ENDLOOP
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT COST &lt;/P&gt;&lt;P&gt;              FROM DSO_TABLE &lt;/P&gt;&lt;P&gt;              INTO int_cost&lt;/P&gt;&lt;P&gt;              FOR ALL ENTRIES IN itab&lt;/P&gt;&lt;P&gt;              WHERE ITEMID EQ itab-ITEMID.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For a numrical field an APPEND, with SORT DELETE ADJACENT DUPLICATES is necessary.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The buffer in the LOOP is then not necessary. However, it the whole routine is executed several times, then&lt;/P&gt;&lt;P&gt;a global table for the buffer is better. Some SELECTs with FOR ALL ENTRIES can make sense plus a buffer access &lt;/P&gt;&lt;P&gt;inside the LOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You see mass data processing is not so simple.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 May 2010 12:51:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/perfomance-optimization-code-select-statement/m-p/7032461#M1499582</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-05-27T12:51:13Z</dc:date>
    </item>
    <item>
      <title>Re: perfomance optimization code - Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/perfomance-optimization-code-select-statement/m-p/7032462#M1499583</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;I have written the code but I keep getting this error &lt;STRONG&gt;E:Type "ITAB_SPC" is unknown&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Data rp TYPE _ty_s_TG_1.
Fields-symbols:  &amp;lt;rp&amp;gt; TYPE _ty_s_TG_1.

data : begin of itab_spc,
       S_ITEMID TYPE /N/ADSO_DSOC00-/N/S_ITEMID,
       STRDCOST TYPE /N/ADSO_DSOC00-/N/S_STRDCOST,
       end of itab_spc.

DATA: it_spc_tab type hashed table of itab_spc with unique key s_itemid,
Data: wa_spc TYPE it_spc_tab.


SELECT /N/S_STRDCOST-/N/S_ITEMID FROM  /N/ADSO_DSOC00 INTO it_spc_tab
       FOR ALL ENTRIES IN RESULT_PACKAGE
        WHERE /N/S_ITEMID EQ rp-/N/S_ITEMID.
ENDSELECT.

LOOP AT RESULT_PACKAGE ASSIGNING &amp;lt;fs_rp&amp;gt;.

  READ TABLE it_spc_tab INTO wa_spc  WITH key S_ itemid = rp-/N/S_ITEMID
binary search.

if sy-subrc eq 0.
         &amp;lt;rp&amp;gt;-/N/S_STRDCOST = wa_spc_STRDCOST.    
 endif.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Matt on May 31, 2010 12:35 PM - when posting code, select it, and then press the &amp;lt; &amp;gt; button.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 May 2010 09:06:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/perfomance-optimization-code-select-statement/m-p/7032462#M1499583</guid>
      <dc:creator>bhat_vaidya2</dc:creator>
      <dc:date>2010-05-31T09:06:57Z</dc:date>
    </item>
    <item>
      <title>Re: perfomance optimization code - Select Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/perfomance-optimization-code-select-statement/m-p/7032463#M1499584</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Define DATA as DATA, and TYPES as TYPES:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPES : begin of itab_spc,
       S_ITEMID TYPE /N/ADSO_DSOC00-/N/S_ITEMID,
       STRDCOST TYPE /N/ADSO_DSOC00-/N/S_STRDCOST,
       end of itab_spc.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 May 2010 10:37:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/perfomance-optimization-code-select-statement/m-p/7032463#M1499584</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2010-05-31T10:37:23Z</dc:date>
    </item>
  </channel>
</rss>

