<?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: Reading internal tables in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/reading-internal-tables/m-p/3718473#M895157</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Read the help on APPEND LINES OF table1 to table3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;MattG.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 01 May 2008 14:46:18 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-05-01T14:46:18Z</dc:date>
    <item>
      <title>Reading internal tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reading-internal-tables/m-p/3718469#M895153</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all&lt;/P&gt;&lt;P&gt;i am using internal table itab1,&lt;/P&gt;&lt;P&gt;i want to add the similar contents of itab1 from itab2 into itab3&lt;/P&gt;&lt;P&gt;how to do it?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;raghvendra bhanap&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 May 2008 08:15:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reading-internal-tables/m-p/3718469#M895153</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-01T08:15:24Z</dc:date>
    </item>
    <item>
      <title>Re: Reading internal tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reading-internal-tables/m-p/3718470#M895154</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;itab2[] = itab1[].&lt;/P&gt;&lt;P&gt;itab3[] = itab1[].&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: raj desai on May 1, 2008 10:46 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 May 2008 08:46:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reading-internal-tables/m-p/3718470#M895154</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-01T08:46:13Z</dc:date>
    </item>
    <item>
      <title>Re: Reading internal tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reading-internal-tables/m-p/3718471#M895155</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab2 into wa_itab2.&lt;/P&gt;&lt;P&gt;read table itab1 into wa_itab1 with key......&lt;/P&gt;&lt;P&gt;if sy-subrc = 0.&lt;/P&gt;&lt;P&gt;append wa_tab1 to itab3.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 May 2008 11:56:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reading-internal-tables/m-p/3718471#M895155</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-01T11:56:45Z</dc:date>
    </item>
    <item>
      <title>Re: Reading internal tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reading-internal-tables/m-p/3718472#M895156</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 Following code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HTAB1 = ITAB1.&lt;/P&gt;&lt;P&gt;REFRESH ITAB3.&lt;/P&gt;&lt;P&gt;LOOP AT ITAB2 ASSIGNING &amp;lt;WA&amp;gt;.&lt;/P&gt;&lt;P&gt;  READ TABLE HTAB1 FROM &amp;lt;WA&amp;gt;&lt;/P&gt;&lt;P&gt;                   TRANSPORTING NO FIELDS.&lt;/P&gt;&lt;P&gt;  IF SY-SUBRC = 0.&lt;/P&gt;&lt;P&gt;    APPEND &amp;lt;WA&amp;gt; TO ITAB3.&lt;/P&gt;&lt;P&gt;  ENDIF.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;FREE HTAB1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Nikita&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 May 2008 12:49:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reading-internal-tables/m-p/3718472#M895156</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-01T12:49:50Z</dc:date>
    </item>
    <item>
      <title>Re: Reading internal tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reading-internal-tables/m-p/3718473#M895157</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Read the help on APPEND LINES OF table1 to table3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;MattG.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 May 2008 14:46:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reading-internal-tables/m-p/3718473#M895157</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-01T14:46:18Z</dc:date>
    </item>
    <item>
      <title>Re: Reading internal tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reading-internal-tables/m-p/3718474#M895158</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;This is a documentation regarding reading internal tables.&lt;/P&gt;&lt;P&gt;Hope this will be useful...&lt;/P&gt;&lt;P&gt;When the size of the record or the number of records in the internal table is large, doing a linear search is time consuming. It is always a good practice to search a record by binary search (Always Sort the table before doing a binary search). The difference is felt especially in the production environment where the live data is usually huge. As of release 4.0 there are new types of internal tables like SORTED and HASHED which can be effectively used to further reduce the search time and processing time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;e.g.	Do not use the following statement:-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Select matnr from mara&lt;/P&gt;&lt;P&gt;Into table i_mara&lt;/P&gt;&lt;P&gt;Where matnr in s_matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;	Select matnr werks from marc&lt;/P&gt;&lt;P&gt;		Into table i_marc&lt;/P&gt;&lt;P&gt;		For all entries in i_mara&lt;/P&gt;&lt;P&gt;		Where matnr eq i_mara-matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;	Loop at I_mara.&lt;/P&gt;&lt;P&gt;		-&lt;/P&gt;&lt;HR originaltext="----------" /&gt;&lt;P&gt;		Read table i_marc with key matnr = I_mara-matnr.&lt;/P&gt;&lt;P&gt;		-&lt;/P&gt;&lt;HR originaltext="----------" /&gt;&lt;P&gt;	Endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Instead use the following statement:-&lt;/P&gt;&lt;P&gt;	Select matnr from mara&lt;/P&gt;&lt;P&gt;		Into table i_mara&lt;/P&gt;&lt;P&gt;		Where matnr in s_matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;							Select matnr werks from marc&lt;/P&gt;&lt;P&gt;								Into table i_marc&lt;/P&gt;&lt;P&gt;								For all entries in i_mara&lt;/P&gt;&lt;P&gt;							    Where matnr eq i_mara-matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;							Sort I_marc by matnr.&lt;/P&gt;&lt;P&gt;							Loop at I_mara.&lt;/P&gt;&lt;P&gt;								-&lt;/P&gt;&lt;HR originaltext="----------" /&gt;&lt;P&gt;								Read table i_marc with key &lt;/P&gt;&lt;P&gt;matnr = I_mara-matnr &lt;/P&gt;&lt;P&gt;binary search.&lt;/P&gt;&lt;P&gt;								-&lt;/P&gt;&lt;HR originaltext="----------" /&gt;&lt;P&gt;							Endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; It is a good practice to search records from internal tables using a binary search. But extreme caution needs to be applied as it may either increase the time or may cause run time termination if it is not sorted.&lt;/P&gt;&lt;P&gt;Always the sort the internal table by the required keys before performing a binary search.                                                                                &lt;/P&gt;&lt;P&gt;e.g.	Do not use the following statement:-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Select matnr from mara&lt;/P&gt;&lt;P&gt;Into table i_mara&lt;/P&gt;&lt;P&gt;Where matnr in s_matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;	Select matnr werks from marc&lt;/P&gt;&lt;P&gt;		Into table i_marc&lt;/P&gt;&lt;P&gt;		For all entries in i_mara&lt;/P&gt;&lt;P&gt;		Where matnr eq i_mara-matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;	Loop at I_mara.&lt;/P&gt;&lt;P&gt;		-&lt;/P&gt;&lt;HR originaltext="----------" /&gt;&lt;P&gt;		Read table i_marc with key matnr = I_mara-matnr binary search.&lt;/P&gt;&lt;P&gt;		-&lt;/P&gt;&lt;HR originaltext="----------" /&gt;&lt;P&gt;	Endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Instead use the following statement:-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;	Select matnr from mara&lt;/P&gt;&lt;P&gt;		Into table i_mara&lt;/P&gt;&lt;P&gt;		Where matnr in s_matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;							Select matnr werks from marc&lt;/P&gt;&lt;P&gt;								Into table i_marc&lt;/P&gt;&lt;P&gt;								For all entries in i_mara&lt;/P&gt;&lt;P&gt;							    Where matnr eq i_mara-matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;							Sort I_marc by matnr.&lt;/P&gt;&lt;P&gt;							Loop at I_mara.&lt;/P&gt;&lt;P&gt;								-&lt;/P&gt;&lt;HR originaltext="----------" /&gt;&lt;P&gt;								Read table i_marc with key &lt;/P&gt;&lt;P&gt;matnr = I_mara-matnr &lt;/P&gt;&lt;P&gt;binary search.&lt;/P&gt;&lt;P&gt;								-&lt;/P&gt;&lt;HR originaltext="----------" /&gt;&lt;P&gt;							Endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is a general practice to use 		Read table &amp;lt;itab&amp;gt;&amp;#133;	This statement populates all the values of the structure in the workarea. &lt;/P&gt;&lt;P&gt;The effect is many fold:-&lt;/P&gt;&lt;P&gt;&amp;#149;	It increases the time to retrieve data from internal table&lt;/P&gt;&lt;P&gt;&amp;#149;	There is large amount of unused data in work area&lt;/P&gt;&lt;P&gt;&amp;#149;	It increases the processing time from work area later&lt;/P&gt;&lt;P&gt;It is always a good practice to retrieve only the required fields. Always use the syntax 	Read table &amp;lt;itab&amp;gt; transporting f1 f2  &amp;#133;  FN &amp;#133;		If just a check is being performed for existence of a record use 	Read table &amp;lt;itab&amp;gt; transporting no fields &amp;#133;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;e.g.	Do not use the following statement:-&lt;/P&gt;&lt;P&gt;data: i_vbak like vbak occurs 0 with header line.&lt;/P&gt;&lt;P&gt;data: i_vbap like vbap occurs 0 with header line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Loop at i_vbak.&lt;/P&gt;&lt;P&gt;	-&lt;/P&gt;&lt;HR originaltext="---------" /&gt;&lt;P&gt;	read table i_vbap with key &lt;/P&gt;&lt;P&gt;vbeln = i_vbak-vbeln binary search.&lt;/P&gt;&lt;P&gt;	If sy-subrc = 0 and i_vbap-posnr = &amp;#145;00010&amp;#146;.&lt;/P&gt;&lt;P&gt;		-&lt;/P&gt;&lt;HR originaltext="---------" /&gt;&lt;P&gt;		-&lt;/P&gt;&lt;HR originaltext="---------" /&gt;&lt;P&gt;	endif.&lt;/P&gt;&lt;P&gt;	-&lt;/P&gt;&lt;HR originaltext="---------" /&gt;&lt;P&gt;Endloop.&lt;/P&gt;&lt;P&gt;Instead use the following statement:-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data: i_vbak like vbak occurs 0 with header line.&lt;/P&gt;&lt;P&gt;data: i_vbap like vbap occurs 0 with header line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Loop at i_vbak.&lt;/P&gt;&lt;P&gt;						-&lt;/P&gt;&lt;HR originaltext="---------" /&gt;&lt;P&gt;						read table i_vbap transporting posnr with key &lt;/P&gt;&lt;P&gt;vbeln = i_vbak-vbeln binary search.&lt;/P&gt;&lt;P&gt;						If sy-subrc = 0 and i_vbap-posnr = &amp;#145;00010&amp;#146;.&lt;/P&gt;&lt;P&gt;							-&lt;/P&gt;&lt;HR originaltext="---------" /&gt;&lt;P&gt;							-&lt;/P&gt;&lt;HR originaltext="---------" /&gt;&lt;P&gt;						endif.&lt;/P&gt;&lt;P&gt;						-&lt;/P&gt;&lt;HR originaltext="---------" /&gt;&lt;P&gt;Endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are many ways in which a select statement can be optimized. Effective use of primary and secondary indexes is one of them. Very little attention is paid especially to the secondary indexes. The following points should be noted before writing a select statement:-&lt;/P&gt;&lt;P&gt;&amp;#149;	Always use the fields in the where clause in the same order as the keys in the database table&lt;/P&gt;&lt;P&gt;&amp;#149;	Define the secondary indexes in the database for the fields which are most frequently used in the programs&lt;/P&gt;&lt;P&gt;&amp;#149;	Always try to use the best possible secondary index in the where clause if it exists&lt;/P&gt;&lt;P&gt;&amp;#149;	Do not have many secondary indexes defined for a table&lt;/P&gt;&lt;P&gt;&amp;#149;	Use as many keys both primary and secondary as possible to optimize data retrieval&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As of release 4.5 it is now possible to define the secondary index in the where clause using %_HINT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;e.g.	Do not use the following statement:-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;	Assuming a secondary index is defined on the field vkorg in table vbak&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;	Select vbeln vkorg from vbak&lt;/P&gt;&lt;P&gt;		Into table i_vbak&lt;/P&gt;&lt;P&gt;		Where vbeln in s_vbeln.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;	Loop at i_vbak.&lt;/P&gt;&lt;P&gt;		Case i_vbak-vkorg.&lt;/P&gt;&lt;P&gt;		When &amp;#145;IJI1&amp;#146;.&lt;/P&gt;&lt;P&gt;			-&lt;/P&gt;&lt;HR originaltext="------------" /&gt;&lt;P&gt;			-&lt;/P&gt;&lt;HR originaltext="------------" /&gt;&lt;P&gt;		When &amp;#145;IJI2&amp;#146;.&lt;/P&gt;&lt;P&gt;			-&lt;/P&gt;&lt;HR originaltext="------------" /&gt;&lt;P&gt;			-&lt;/P&gt;&lt;HR originaltext="------------" /&gt;&lt;P&gt;		Endcase.&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;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Instead use the following statement:-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;							Select vbeln vkorg from vbak&lt;/P&gt;&lt;P&gt;								Into table i_vbak&lt;/P&gt;&lt;P&gt;								Where vbeln in s_vbeln and&lt;/P&gt;&lt;P&gt;									Vkorg in (&amp;#145;IJI1&amp;#146;,&amp;#146;IJI2&amp;#146;).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;							Loop at i_vbak.&lt;/P&gt;&lt;P&gt;								Case i_vbak-vkorg.&lt;/P&gt;&lt;P&gt;								When &amp;#145;IJI1&amp;#146;.&lt;/P&gt;&lt;P&gt;									-&lt;/P&gt;&lt;HR originaltext="------------" /&gt;&lt;P&gt;									-&lt;/P&gt;&lt;HR originaltext="------------" /&gt;&lt;P&gt;								When &amp;#145;IJI2&amp;#146;.&lt;/P&gt;&lt;P&gt;									-&lt;/P&gt;&lt;HR originaltext="------------" /&gt;&lt;P&gt;									-&lt;/P&gt;&lt;HR originaltext="------------" /&gt;&lt;P&gt;								Endcase.&lt;/P&gt;&lt;P&gt;							Endloop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 May 2008 06:37:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reading-internal-tables/m-p/3718474#M895158</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-02T06:37:19Z</dc:date>
    </item>
    <item>
      <title>Re: Reading internal tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reading-internal-tables/m-p/3718475#M895159</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;This is a documentation regarding reading internal tables.&lt;/P&gt;&lt;P&gt;Hope this will be useful...&lt;/P&gt;&lt;P&gt;When the size of the record or the number of records in the internal table is large, doing a linear search is time consuming. It is always a good practice to search a record by binary search (Always Sort the table before doing a binary search). The difference is felt especially in the production environment where the live data is usually huge. As of release 4.0 there are new types of internal tables like SORTED and HASHED which can be effectively used to further reduce the search time and processing time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;e.g.	Do not use the following statement:-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Select matnr from mara&lt;/P&gt;&lt;P&gt;Into table i_mara&lt;/P&gt;&lt;P&gt;Where matnr in s_matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;	Select matnr werks from marc&lt;/P&gt;&lt;P&gt;		Into table i_marc&lt;/P&gt;&lt;P&gt;		For all entries in i_mara&lt;/P&gt;&lt;P&gt;		Where matnr eq i_mara-matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;	Loop at I_mara.&lt;/P&gt;&lt;P&gt;		-&lt;/P&gt;&lt;HR originaltext="----------" /&gt;&lt;P&gt;		Read table i_marc with key matnr = I_mara-matnr.&lt;/P&gt;&lt;P&gt;		-&lt;/P&gt;&lt;HR originaltext="----------" /&gt;&lt;P&gt;	Endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Instead use the following statement:-&lt;/P&gt;&lt;P&gt;	Select matnr from mara&lt;/P&gt;&lt;P&gt;		Into table i_mara&lt;/P&gt;&lt;P&gt;		Where matnr in s_matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;							Select matnr werks from marc&lt;/P&gt;&lt;P&gt;								Into table i_marc&lt;/P&gt;&lt;P&gt;								For all entries in i_mara&lt;/P&gt;&lt;P&gt;							    Where matnr eq i_mara-matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;							Sort I_marc by matnr.&lt;/P&gt;&lt;P&gt;							Loop at I_mara.&lt;/P&gt;&lt;P&gt;								-&lt;/P&gt;&lt;HR originaltext="----------" /&gt;&lt;P&gt;								Read table i_marc with key &lt;/P&gt;&lt;P&gt;matnr = I_mara-matnr &lt;/P&gt;&lt;P&gt;binary search.&lt;/P&gt;&lt;P&gt;								-&lt;/P&gt;&lt;HR originaltext="----------" /&gt;&lt;P&gt;							Endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; It is a good practice to search records from internal tables using a binary search. But extreme caution needs to be applied as it may either increase the time or may cause run time termination if it is not sorted.&lt;/P&gt;&lt;P&gt;Always the sort the internal table by the required keys before performing a binary search.                                                                                &lt;/P&gt;&lt;P&gt;e.g.	Do not use the following statement:-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Select matnr from mara&lt;/P&gt;&lt;P&gt;Into table i_mara&lt;/P&gt;&lt;P&gt;Where matnr in s_matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;	Select matnr werks from marc&lt;/P&gt;&lt;P&gt;		Into table i_marc&lt;/P&gt;&lt;P&gt;		For all entries in i_mara&lt;/P&gt;&lt;P&gt;		Where matnr eq i_mara-matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;	Loop at I_mara.&lt;/P&gt;&lt;P&gt;		-&lt;/P&gt;&lt;HR originaltext="----------" /&gt;&lt;P&gt;		Read table i_marc with key matnr = I_mara-matnr binary search.&lt;/P&gt;&lt;P&gt;		-&lt;/P&gt;&lt;HR originaltext="----------" /&gt;&lt;P&gt;	Endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Instead use the following statement:-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;	Select matnr from mara&lt;/P&gt;&lt;P&gt;		Into table i_mara&lt;/P&gt;&lt;P&gt;		Where matnr in s_matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;							Select matnr werks from marc&lt;/P&gt;&lt;P&gt;								Into table i_marc&lt;/P&gt;&lt;P&gt;								For all entries in i_mara&lt;/P&gt;&lt;P&gt;							    Where matnr eq i_mara-matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;							Sort I_marc by matnr.&lt;/P&gt;&lt;P&gt;							Loop at I_mara.&lt;/P&gt;&lt;P&gt;								-&lt;/P&gt;&lt;HR originaltext="----------" /&gt;&lt;P&gt;								Read table i_marc with key &lt;/P&gt;&lt;P&gt;matnr = I_mara-matnr &lt;/P&gt;&lt;P&gt;binary search.&lt;/P&gt;&lt;P&gt;								-&lt;/P&gt;&lt;HR originaltext="----------" /&gt;&lt;P&gt;							Endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is a general practice to use 		Read table &amp;lt;itab&amp;gt;&amp;#133;	This statement populates all the values of the structure in the workarea. &lt;/P&gt;&lt;P&gt;The effect is many fold:-&lt;/P&gt;&lt;P&gt;&amp;#149;	It increases the time to retrieve data from internal table&lt;/P&gt;&lt;P&gt;&amp;#149;	There is large amount of unused data in work area&lt;/P&gt;&lt;P&gt;&amp;#149;	It increases the processing time from work area later&lt;/P&gt;&lt;P&gt;It is always a good practice to retrieve only the required fields. Always use the syntax 	Read table &amp;lt;itab&amp;gt; transporting f1 f2  &amp;#133;  FN &amp;#133;		If just a check is being performed for existence of a record use 	Read table &amp;lt;itab&amp;gt; transporting no fields &amp;#133;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;e.g.	Do not use the following statement:-&lt;/P&gt;&lt;P&gt;data: i_vbak like vbak occurs 0 with header line.&lt;/P&gt;&lt;P&gt;data: i_vbap like vbap occurs 0 with header line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Loop at i_vbak.&lt;/P&gt;&lt;P&gt;	-&lt;/P&gt;&lt;HR originaltext="---------" /&gt;&lt;P&gt;	read table i_vbap with key &lt;/P&gt;&lt;P&gt;vbeln = i_vbak-vbeln binary search.&lt;/P&gt;&lt;P&gt;	If sy-subrc = 0 and i_vbap-posnr = &amp;#145;00010&amp;#146;.&lt;/P&gt;&lt;P&gt;		-&lt;/P&gt;&lt;HR originaltext="---------" /&gt;&lt;P&gt;		-&lt;/P&gt;&lt;HR originaltext="---------" /&gt;&lt;P&gt;	endif.&lt;/P&gt;&lt;P&gt;	-&lt;/P&gt;&lt;HR originaltext="---------" /&gt;&lt;P&gt;Endloop.&lt;/P&gt;&lt;P&gt;Instead use the following statement:-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data: i_vbak like vbak occurs 0 with header line.&lt;/P&gt;&lt;P&gt;data: i_vbap like vbap occurs 0 with header line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Loop at i_vbak.&lt;/P&gt;&lt;P&gt;						-&lt;/P&gt;&lt;HR originaltext="---------" /&gt;&lt;P&gt;						read table i_vbap transporting posnr with key &lt;/P&gt;&lt;P&gt;vbeln = i_vbak-vbeln binary search.&lt;/P&gt;&lt;P&gt;						If sy-subrc = 0 and i_vbap-posnr = &amp;#145;00010&amp;#146;.&lt;/P&gt;&lt;P&gt;							-&lt;/P&gt;&lt;HR originaltext="---------" /&gt;&lt;P&gt;							-&lt;/P&gt;&lt;HR originaltext="---------" /&gt;&lt;P&gt;						endif.&lt;/P&gt;&lt;P&gt;						-&lt;/P&gt;&lt;HR originaltext="---------" /&gt;&lt;P&gt;Endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are many ways in which a select statement can be optimized. Effective use of primary and secondary indexes is one of them. Very little attention is paid especially to the secondary indexes. The following points should be noted before writing a select statement:-&lt;/P&gt;&lt;P&gt;&amp;#149;	Always use the fields in the where clause in the same order as the keys in the database table&lt;/P&gt;&lt;P&gt;&amp;#149;	Define the secondary indexes in the database for the fields which are most frequently used in the programs&lt;/P&gt;&lt;P&gt;&amp;#149;	Always try to use the best possible secondary index in the where clause if it exists&lt;/P&gt;&lt;P&gt;&amp;#149;	Do not have many secondary indexes defined for a table&lt;/P&gt;&lt;P&gt;&amp;#149;	Use as many keys both primary and secondary as possible to optimize data retrieval&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As of release 4.5 it is now possible to define the secondary index in the where clause using %_HINT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;e.g.	Do not use the following statement:-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;	Assuming a secondary index is defined on the field vkorg in table vbak&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;	Select vbeln vkorg from vbak&lt;/P&gt;&lt;P&gt;		Into table i_vbak&lt;/P&gt;&lt;P&gt;		Where vbeln in s_vbeln.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;	Loop at i_vbak.&lt;/P&gt;&lt;P&gt;		Case i_vbak-vkorg.&lt;/P&gt;&lt;P&gt;		When &amp;#145;IJI1&amp;#146;.&lt;/P&gt;&lt;P&gt;			-&lt;/P&gt;&lt;HR originaltext="------------" /&gt;&lt;P&gt;			-&lt;/P&gt;&lt;HR originaltext="------------" /&gt;&lt;P&gt;		When &amp;#145;IJI2&amp;#146;.&lt;/P&gt;&lt;P&gt;			-&lt;/P&gt;&lt;HR originaltext="------------" /&gt;&lt;P&gt;			-&lt;/P&gt;&lt;HR originaltext="------------" /&gt;&lt;P&gt;		Endcase.&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;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Instead use the following statement:-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;							Select vbeln vkorg from vbak&lt;/P&gt;&lt;P&gt;								Into table i_vbak&lt;/P&gt;&lt;P&gt;								Where vbeln in s_vbeln and&lt;/P&gt;&lt;P&gt;									Vkorg in (&amp;#145;IJI1&amp;#146;,&amp;#146;IJI2&amp;#146;).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;							Loop at i_vbak.&lt;/P&gt;&lt;P&gt;								Case i_vbak-vkorg.&lt;/P&gt;&lt;P&gt;								When &amp;#145;IJI1&amp;#146;.&lt;/P&gt;&lt;P&gt;									-&lt;/P&gt;&lt;HR originaltext="------------" /&gt;&lt;P&gt;									-&lt;/P&gt;&lt;HR originaltext="------------" /&gt;&lt;P&gt;								When &amp;#145;IJI2&amp;#146;.&lt;/P&gt;&lt;P&gt;									-&lt;/P&gt;&lt;HR originaltext="------------" /&gt;&lt;P&gt;									-&lt;/P&gt;&lt;HR originaltext="------------" /&gt;&lt;P&gt;								Endcase.&lt;/P&gt;&lt;P&gt;							Endloop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 May 2008 06:37:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reading-internal-tables/m-p/3718475#M895159</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-02T06:37:56Z</dc:date>
    </item>
  </channel>
</rss>

