<?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: tables in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/tables/m-p/2312935#M506805</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Binary search is very useful to imrove performances during read.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Iam giving u a simple example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;first we will sort the table with key which is used in reading n then we will read.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: var1(6) TYPE c VALUE 'ABCDEF',&lt;/P&gt;&lt;P&gt;      var2(5) TYPE c VALUE 'GHIJK',&lt;/P&gt;&lt;P&gt;      result(12) TYPE c .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TYPES: BEGIN OF ty_vbak,&lt;/P&gt;&lt;P&gt;vbeln TYPE vbak-vbeln,&lt;/P&gt;&lt;P&gt;END OF ty_vbak,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BEGIN OF ty_vbap,&lt;/P&gt;&lt;P&gt;vbeln TYPE vbap-vbeln,&lt;/P&gt;&lt;P&gt;posnr TYPE vbap-posnr,&lt;/P&gt;&lt;P&gt;END OF ty_vbap.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: it_vbak TYPE STANDARD TABLE OF ty_vbak,&lt;/P&gt;&lt;P&gt;it_vbap TYPE STANDARD TABLE OF ty_vbap,&lt;/P&gt;&lt;P&gt;it_out TYPE STANDARD TABLE OF ty_vbak,&lt;/P&gt;&lt;P&gt;wa_vbak TYPE  ty_vbak,&lt;/P&gt;&lt;P&gt;wa_vbap TYPE  ty_vbap,&lt;/P&gt;&lt;P&gt;wa_out TYPE  ty_vbak.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT vbeln INTO&lt;/P&gt;&lt;P&gt;TABLE it_vbak FROM vbak.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF  it_vbak[] IS NOT INITIAL.&lt;/P&gt;&lt;P&gt;SELECT vbeln posnr&lt;/P&gt;&lt;P&gt;into table it_vbap&lt;/P&gt;&lt;P&gt;from vbap&lt;/P&gt;&lt;P&gt;for all entries IN it_vbak&lt;/P&gt;&lt;P&gt;where vbeln = it_vbak-vbeln.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort: it_vbap by vbeln.&lt;/P&gt;&lt;P&gt;loop at it_vbak into wa_vbak.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;read table it_vbap into wa_vbap&lt;/P&gt;&lt;P&gt;with key vbeln = wa_vbak-vbeln&lt;/P&gt;&lt;P&gt;binary search.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if sy-subrc is initial.&lt;/P&gt;&lt;P&gt;wa_out-vbeln = wa_vbap-vbeln.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;clear: wa_vbap,wa_out,wa_vbak.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;sudha&lt;/P&gt;&lt;P&gt;reward points if useful&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 31 May 2007 09:02:17 GMT</pubDate>
    <dc:creator>S0025444845</dc:creator>
    <dc:date>2007-05-31T09:02:17Z</dc:date>
    <item>
      <title>tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/tables/m-p/2312928#M506798</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi guru's,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; wat is the use of binary search? and where we can use this?provide me a sample code.if use full .................full points............urgetnt&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanx n regards,&lt;/P&gt;&lt;P&gt;lokanadhan.k&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 May 2007 08:00:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/tables/m-p/2312928#M506798</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-31T08:00:06Z</dc:date>
    </item>
    <item>
      <title>Re: tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/tables/m-p/2312929#M506799</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can use BINARY SEARC with READ statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is used for faster searching. &amp;lt;b&amp;gt;It can be used only when table is sorted&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SORT ITAB2.&lt;/P&gt;&lt;P&gt;LOOP AT ITAB1.&lt;/P&gt;&lt;P&gt;READ TABLE ITAB2 WITH KEY FIELD1 = ITAB1-FIELD1 BINARY SEARCH.&lt;/P&gt;&lt;P&gt;IF SY-SUBRC = 0.&lt;/P&gt;&lt;P&gt;*Required code&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, 31 May 2007 08:06:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/tables/m-p/2312929#M506799</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-31T08:06:33Z</dc:date>
    </item>
    <item>
      <title>Re: tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/tables/m-p/2312930#M506800</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;Read statement fetches the record from the internal table using implicit key or explicit key. When no key or index is specified for the search criteria the key in the WA of the internal table is used implicitly for searching. SAP recommends explicit search criteria. Here the key or index is explicitly specified which is used for searching the records from internal table. This is faster than an implicit search.&lt;/P&gt;&lt;P&gt;When reading a single record in an internal table, the READ TABLE WITH KEY is not a direct READ.  Therefore, SORT the table and use READ TABLE WITH KEY BINARY SEARCH. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i)	Do not 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;	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;&lt;/P&gt;&lt;P&gt;ii)	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;	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;***do reward if usefull&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;vijay&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 May 2007 08:06:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/tables/m-p/2312930#M506800</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-31T08:06:41Z</dc:date>
    </item>
    <item>
      <title>Re: tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/tables/m-p/2312931#M506801</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;it is used in place of simple read (if table contains more than 300 records)to increase performance. &lt;/P&gt;&lt;P&gt;example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;       read table it_results_final assigning &amp;lt;fs_output_final&amp;gt;&lt;/P&gt;&lt;P&gt;          with key ordkey     = &amp;lt;fs_output_tab&amp;gt;-ordkey&lt;/P&gt;&lt;P&gt;                   itm_number = &amp;lt;fs_output_tab&amp;gt;-itm_number&lt;/P&gt;&lt;P&gt;                   binary search.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However you should ensure that the table is sorted by the fields with which you are doing the read else it will not work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;Sooness&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 May 2007 08:09:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/tables/m-p/2312931#M506801</guid>
      <dc:creator>dev_parbutteea</dc:creator>
      <dc:date>2007-05-31T08:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/tables/m-p/2312932#M506802</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;There are different types of searches that you can use while searching  data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example you have binary search, linear search etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why use Binary search ?&lt;/P&gt;&lt;P&gt;Time taken to search the data is less with Binary search than linear search.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Binary search:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The primary requisite to apply binary search on an internal table is that table should be sorted by some field.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now assume that you have some internal table and would like to search some particular field with some particular key , then you will sort the internal table and then read this table for a particular value &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code snippet:&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      Account Assignment in Purchasing Document&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;          CLEAR ls_acc_ass_purdoc.&lt;/P&gt;&lt;P&gt;          READ TABLE pa_acc_ass_purdoc INTO ls_acc_ass_purdoc&lt;/P&gt;&lt;P&gt;                          WITH KEY ebeln = ls_pur_doc_head_item-ebeln&lt;/P&gt;&lt;P&gt;                                   ebelp = ls_pur_doc_head_item-ebelp&lt;/P&gt;&lt;P&gt;                                   BINARY SEARCH.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 May 2007 08:11:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/tables/m-p/2312932#M506802</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-31T08:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/tables/m-p/2312933#M506803</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;If you read entries from standard tables using a key other than the default key, you can use a binary search instead of the normal linear search. To do this, include the addition BINARY SEARCH in the corresponding READ statements.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;READ TABLE &amp;lt;itab&amp;gt; WITH KEY &amp;lt;k1&amp;gt; = &amp;lt;f1&amp;gt;... &amp;lt;kn&amp;gt; = &amp;lt;fn&amp;gt; &amp;lt;result&amp;gt; &lt;/P&gt;&lt;P&gt;                                                       BINARY SEARCH.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The standard table must be sorted in ascending order by the specified search key. The BINARY SEARCH addition means that you can access an entry in a standard table by its key as quickly as you would be able to in a sorted table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;U CAN TRY BELOW CODE&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: BEGIN OF line,&lt;/P&gt;&lt;P&gt;        col1 TYPE i,&lt;/P&gt;&lt;P&gt;        col2 TYPE i,&lt;/P&gt;&lt;P&gt;      END OF line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA itab LIKE STANDARD TABLE OF line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DO 4 TIMES.&lt;/P&gt;&lt;P&gt;  line-col1 = sy-index.&lt;/P&gt;&lt;P&gt;  line-col2 = sy-index ** 2.&lt;/P&gt;&lt;P&gt;  APPEND line TO itab.&lt;/P&gt;&lt;P&gt;ENDDO.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SORT itab BY col2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;READ TABLE itab WITH KEY col2 = 16 INTO line BINARY SEARCH.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;WRITE: 'SY-SUBRC =', sy-subrc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The output is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SY-SUBRC =    0&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Madhukar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 May 2007 08:21:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/tables/m-p/2312933#M506803</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-31T08:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/tables/m-p/2312934#M506804</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The search takes place as follows for the individual table types : &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;standard tables are subject to a linear search. If the addition BINARY SEARCH is specified, the search is binary instead of linear. This considerably reduces the runtime of the search for larger tables (from approximately 100 entries upwards). For the binary search, the table must be sorted by the specified search key in ascending order. Otherwise the search will not find the correct row. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sorted tables are subject to a binary search if the specified search key is or includes a starting field of the table key. Otherwise it is linear. If the specified search key is or inclucdes an starting field of the table key, the addition BINARY SEARCH can be specified for sorted tables, but has no effect. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For hashed tables, the hash algorithm is used if the specified search key includes the table key. Otherwise the search is linear. The addition BINARY SEARCH is not permitted for hashed tables. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Notes: &lt;/P&gt;&lt;P&gt;If a name field for naming a component comp is initial, the first line that fits the rest of the search key is read. If all name fields are initial, the first row of the internal table is read. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the addition BINARY SEARCH is used, the READ statement executes an index access. This can therefore only be used for appropriately typed tables (generic type INDEX TABLE). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Even with a binary search (addition BINARY SEARCH is used for standard tables, automatically for sorted tables), if there are several hits (because of an incompletely specified search key or because there are duplicate entries in the table), then the first hit in terms of the sequence of the rows is always returned, that is, the row with the smallest index. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;example's&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Binary Search in Standard Tables 

If you read entries from standard tables using a key other than the default key, you can use a binary search instead of the normal linear search. To do this, include the addition BINARY SEARCH in the corresponding READ statements. 

READ TABLE &amp;lt;itab&amp;gt; WITH KEY = &amp;lt;f&amp;gt; &amp;lt;result&amp;gt; BINARY SEARCH.

and

READ TABLE &amp;lt;itab&amp;gt; WITH KEY &amp;lt;k1&amp;gt; = &amp;lt;f1&amp;gt; ... &amp;lt;kn&amp;gt; = &amp;lt;fn&amp;gt; &amp;lt;result&amp;gt; 
                                                       BINARY SEARCH.

The standard table must be sorted in ascending order by the specified search key. The BINARY SEARCH addition means that you can access an entry in a standard table by its key as quickly as you would be able to in a sorted table. 

Example
DATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.

DATA ITAB LIKE STANDARD TABLE OF LINE.

DO 4 TIMES.
  LINE-COL1 = SY-INDEX.
  LINE-COL2 = SY-INDEX ** 2.
  APPEND LINE TO ITAB.
ENDDO.

SORT ITAB BY COL2.

READ TABLE ITAB WITH KEY COL2 = 16 INTO LINE BINARY SEARCH.

WRITE: 'SY-SUBRC =', SY-SUBRC.

The output is: 

SY-SUBRC =    0

The program fills a standard table with a list of square numbers and sorts them into ascending order by field COL2. The READ statement uses a binary search to look for and find the line in the table where COL2 has the value 16. 

 

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;reward points  if it is usefull ....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;girish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 May 2007 08:50:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/tables/m-p/2312934#M506804</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-31T08:50:50Z</dc:date>
    </item>
    <item>
      <title>Re: tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/tables/m-p/2312935#M506805</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Binary search is very useful to imrove performances during read.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Iam giving u a simple example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;first we will sort the table with key which is used in reading n then we will read.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: var1(6) TYPE c VALUE 'ABCDEF',&lt;/P&gt;&lt;P&gt;      var2(5) TYPE c VALUE 'GHIJK',&lt;/P&gt;&lt;P&gt;      result(12) TYPE c .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TYPES: BEGIN OF ty_vbak,&lt;/P&gt;&lt;P&gt;vbeln TYPE vbak-vbeln,&lt;/P&gt;&lt;P&gt;END OF ty_vbak,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BEGIN OF ty_vbap,&lt;/P&gt;&lt;P&gt;vbeln TYPE vbap-vbeln,&lt;/P&gt;&lt;P&gt;posnr TYPE vbap-posnr,&lt;/P&gt;&lt;P&gt;END OF ty_vbap.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: it_vbak TYPE STANDARD TABLE OF ty_vbak,&lt;/P&gt;&lt;P&gt;it_vbap TYPE STANDARD TABLE OF ty_vbap,&lt;/P&gt;&lt;P&gt;it_out TYPE STANDARD TABLE OF ty_vbak,&lt;/P&gt;&lt;P&gt;wa_vbak TYPE  ty_vbak,&lt;/P&gt;&lt;P&gt;wa_vbap TYPE  ty_vbap,&lt;/P&gt;&lt;P&gt;wa_out TYPE  ty_vbak.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT vbeln INTO&lt;/P&gt;&lt;P&gt;TABLE it_vbak FROM vbak.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF  it_vbak[] IS NOT INITIAL.&lt;/P&gt;&lt;P&gt;SELECT vbeln posnr&lt;/P&gt;&lt;P&gt;into table it_vbap&lt;/P&gt;&lt;P&gt;from vbap&lt;/P&gt;&lt;P&gt;for all entries IN it_vbak&lt;/P&gt;&lt;P&gt;where vbeln = it_vbak-vbeln.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort: it_vbap by vbeln.&lt;/P&gt;&lt;P&gt;loop at it_vbak into wa_vbak.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;read table it_vbap into wa_vbap&lt;/P&gt;&lt;P&gt;with key vbeln = wa_vbak-vbeln&lt;/P&gt;&lt;P&gt;binary search.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if sy-subrc is initial.&lt;/P&gt;&lt;P&gt;wa_out-vbeln = wa_vbap-vbeln.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;clear: wa_vbap,wa_out,wa_vbak.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;sudha&lt;/P&gt;&lt;P&gt;reward points if useful&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 May 2007 09:02:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/tables/m-p/2312935#M506805</guid>
      <dc:creator>S0025444845</dc:creator>
      <dc:date>2007-05-31T09:02:17Z</dc:date>
    </item>
    <item>
      <title>Re: tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/tables/m-p/2312936#M506806</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;select field1 from itab1.&lt;/P&gt;&lt;P&gt;SORT ITAB1 by field1.&lt;/P&gt;&lt;P&gt;LOOP AT ITAB1.&lt;/P&gt;&lt;P&gt;READ TABLE ITAB2 WITH KEY FIELD1 = ITAB1-FIELD1 BINARY SEARCH.&lt;/P&gt;&lt;P&gt;IF SY-SUBRC = 0.&lt;/P&gt;&lt;P&gt;*write what you want to do with the selected data here&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;ENDLOOP. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Binary search is faster than normal search. The reason is, it uses a special searching algorithm. First you need to sort the required field. for example, the itab1-field1 in the above code has 1,2,3,4,5&lt;/P&gt;&lt;P&gt;and your itab2 has field1 value as 4. &lt;/P&gt;&lt;P&gt;so first, the program takes the middle value in itab1, say 3.&lt;/P&gt;&lt;P&gt;then it compares this with itab2-field. now 4 is greater than 3, so the program knows the value could be greater than 3, that is 4 or 5. it proceeds like this and finds the record&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Arun&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 May 2007 09:13:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/tables/m-p/2312936#M506806</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-31T09:13:53Z</dc:date>
    </item>
  </channel>
</rss>

