A little urgent when to use binary search.

Hi evryone,
Plz let me know under what kind of conditions can we use binary search addition cause if I use it for every read statement the database acees in se30 goes higher than normal.
If i randomly select only a few big read table statements the database acees in se30 goes is slightly lesser.
But I some how dont know where to use binary search and where not to with read statements.
Expecting an early reply.
Rgds,
Anu

hi,
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 <itab> WITH KEY <k1> = <f1>... <kn> = <fn> <result>
                                                       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.
REPORT demo_int_tables_read_index_bin.
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
reward if useful.
Thanks,
Madhukar

Similar Messages

  • When to use binary search ... little urgent.

    Hi evryone,
    Plz let me know under what kind of conditions can we use binary search addition cause if I use it for every read statement the database acees in se30 goes higher than normal.
    If i randomly select only a few big read table statements the database acees in se30 goes is slightly lesser.
    But I some how dont know where to use binary search and where not to with read statements.
    Expecting an early reply.
    Rgds,
    Anu

    Hi,
    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 <itab> WITH KEY <k1> = <f1>... <kn> = <fn> 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.
    BINARY SEARCH approaches the middle entry in the table, decides if it matches, or lexically greater than or equal to the key being searched. It accordingly skips either the top or bottom part of the internal table and searches the other half. It repeats this process till it finds the row.
    Using BINARY SEARCH with READ is the most efficient way to read standard internal tables which are sorted by the key used to search them
    BINARY SEARCH addition when reading a sorted table is not required, as it happens by default. It makes a good difference in performance if you are reading a large standard internal table without sorting and reading by BINARY SEARCH.
    Regards,
    Padmam.

  • Can't we use Binary SEARCH  for TYPE SORTED TABLE?(Performance Improvement)

    Hi Expert!
                       I have declare a sorted type table with NON -UNIQUE, and want to use Binary search in read statement. But while  using bunary search in read statement I'm facing an error. The ERROR is
    "Table LI_MARC is a SORTED TABLE or INDEX TABLE. The BINARY SEARCH
    addition is only allowed for these tables if the key specified is an
    initial part of the table key."
    Please find detail
    TYES: tt_marc  TYPE SORTED TABLE OF marc   WITH NON-UNIQUE KEY matnr,werks.
    DATA: li_marc type tt_marc.
    READ TABLE li_marc INTO marc WITH KEY matnr = i_mbew-matnr     
                                                                          werks = i_mbew-bwkey BINARY SEARCH . 
    To my understanding , there is no need to mention Bianry Search  for sorted table TYPE. Please  let me know can  i use ?

    Hello,
    there is no need to mention Bianry Search for sorted table TYPE.
    Yes, this is because for SORTED TABLEs binary search algorithm is used by default for READ TABLE. Although you can use BINARY SEARCH addition but it's use is redundant.
    As for your case you've defined the KEY fields incorrectly There shouldn't be any "comma(s)" between the fields.
    TYPES: tt_marc TYPE SORTED TABLE OF marc WITH NON-UNIQUE KEY matnr werks.
    When you define it with commas
    TYPES: tt_marc TYPE SORTED TABLE OF marc WITH NON-UNIQUE KEY matnr, werks.
    the result is something like this:
    TYPES: tt_marc TYPE SORTED TABLE OF marc WITH NON-UNIQUE KEY matnr.
    TYPES: werks.
    Hence you were getting the syntax error!
    BR,
    Suhas
    PS: As for MARC you can use UNIQUE KEY addition because MATNR & WERKS are the key fields in the table.

  • AVG Secure Search appears when I use Google Search from my Home page only.

    My home page is the Firefox default page with the Google searchbar. I like getting occasional messages from Firefox when I log in so I don't want to change my homepage. However, when I use the searchbar ''on my homepage only'', I get the unsatisfactory AVG Secure Search results.
    UPDATE: I now realize all the troubleshooting information I included in my original question appears under the "More System Details" link next to the question, not in the body of the question. I have copied it here to make it easier to see what I have already done to try to solve the problem, as well as describe the one clue I have that may be relevant:
    I have tried all the fixes on various threads, but my about:config is now pristine (no avg or isearch mentions; keyword.url is default). Closest solution is that at https://support.mozilla.org/en-US/questions/866327 , which requires changing my home page.
    Oddly, AVG Secure Search is ''not'' a problem when I use the Google toolbar or search from the Google website, only when I use the search bar that appears on my home (start) page. This is true even when I return to my home page--if I search from the Google search bar in the middle of the page, I get sent to AVG Safe Search. (isearch.avg.com).
    I read in one thread a suggestion to delete my chromeappsstore.sqlite file in my Profile folder. As promised, Firefox created a new one when I restarted it; however, the search bar in the middle of my home home page did not work at all. Tried this three times before restoring my original.
    I do not have an application that will open a sqlite file, but I tried doing so in Excel and found a cell containing the following:
    emoh.:moz-safe-aboutsearch-engine{"name":"AVG Secure Search","searchUrl":"http://isearch.avg.com/search?cid={7A3C25A0-E345-4507-AA31-D98F596A81A9}&mid=c48135235ba247d18ac1d14b344db451-addd29eab2809954d5abdf0b991a5b911a297819&ds=is015&lang=en&v=10.0.0.7&pr=sa&d=&sap=dsp&q=_searchTerms_"}
    I have no clue what that means, but it is the only thing I can find related to Firefox that still mentions AVG and isearch.avg.com.
    At this point my best guess (but it is a guess) is that the chromeappsstore.sqlite file is a key to the complete solution, but I do not have enough knowledge to go beyond and address it. I appreciate any help you anyone can offer.

    Here is the way to get rid of the problem once and for all:
    http://forums.avg.com/ww-en/avg-forums?sec=thread&act=show&id=196402#post_196402

  • I accidentally quit my CC on my Macbook pro and now the cloud icon is grayed out and every time I hover over it with the mouse I get the spinning beach ball of death on the icon. I have no idea how to open it because when I use spotlight search to open it

    I accidentally quit my CC on my Macbook pro and now the cloud icon is grayed out and every time I hover over it with the mouse I get the spinning beach ball of death on the icon. I have no idea how to open it because when I use spotlight search to open it it gives me a message saying "Creative Cloud is not open anymore" help!

    Since you didn't include any pertinent info such as the Mac model and OS version you are running, here is some general information:
    Mac OS X: Gray screen appears during startup
    Depending on which OS yours came with originally - and which OS you are now running - you would either need your original install disks - you can call Apple for replacements by giving them your serial number. Or you may be able to reinstall the OS by using recovery (again, depends on which model/which OS).

  • How do i search for a photo album when i use the search facility on my iPad or iPhone it will not find photo albums of a given name can anyone help

    how do i search for a photo album when i use the search facility on my iPad or iPhone it will not find photo albums of a given name can anyone help

    Photo albums are not searched by Spotlight Search.  Go to Settings > General > Spotlight Search to see and reorder the available search items.
    For more details, see page 12 of the iPad iOS 5.1 User Guide

  • I am looking for a specific photo in my event folder, it does not show up, yet when I use the search feature, the photo is there.  Why doesn't it show up in the folder?

    I am looking for a specific photo in my event folder, it does not show up, yet when I use the search feature the picture is there.  Why doesn't it show up in the folder?

    What system and iPhoto version are you running?
    If your're using iPhoto 9 or later  Command (right) - click on the photo in the search window and select Show Event in the Contextual menu. 
    That will take you to the event where the photo is.
    OT

  • Reg : Read statement using Binary Search....

    I have an Internal Table as below
    Value           Description
    100               Product
    2008             Production Year
    05                 Production Month
    I am using Read statement with Binary Search for getting Production Month.
    Read table itab with key Description = 'Production Month' binary search.
    I am getting sy-subrc as 4 eventhough data is present in the table for Production Month.
    What may be the problem.

    Hi suganya,
    use
    sort table itab ascending by <production month>.    
    Read table itab with key description = <production month> binary search.
    Remember always, while using binary search always sort the internal table.
    Regards,
    Sakthi.

  • When i use a search engine like google, yahoo, etc., when I click on the link I am immediately redirected to a different site. How to I prevent this?

    when i use a search engine like google, yahoo, etc., when I click on the link, I am immediately redirected to another site. Many times I must hit "back", and click on the link again. Sometimes I am redirected again to another and different site. If I go back again and re-click, it will then take me to the link that is listed.

    Install, update, and run these programs in this order. They are listed in order of efficacy.<br />'''''(Not all programs detect the same Malware, so you may need to run them all to solve your problem.)''''' <br />These programs are all free for personal use, but some have limited functionality in the "free mode" - but those are features you really don't need to find and remove the problem that you have.<br />
    ''Note: If your Malware infection is bad enough and you are mis-directed to URL's other than what is posted, you may have to use a different PC to download these programs and use a USB stick to transfer them to the afflicted PC.''
    Malwarebytes' Anti-Malware - [http://www.malwarebytes.org/mbam.php] <br />
    SuperAntispyware - [http://www.superantispyware.com/] <br />
    AdAware - [http://www.lavasoftusa.com/software/adaware/] <br />
    Spybot Search & Destroy - [http://www.safer-networking.org/en/index.html] <br />
    Windows Defender: Home Page - [http://www.microsoft.com/windows/products/winfamily/defender/default.mspx]<br />
    Also, if you have a search engine re-direct problem, see this:<br />
    http://deletemalware.blogspot.com/2010/02/remove-google-redirect-virus.html
    If these don't find it or can't clear it, post in one of these forums for specialized malware removal help: <br />
    [http://www.spywarewarrior.com/index.php] <br />
    [http://forum.aumha.org/] <br />
    [http://www.spywareinfoforum.com/] <br />
    [http://bleepingcomputer.com]

  • READ using Binary Search

    Hi,
    Is it necessary to use all the sorted keys in READ using BINARY SEARCH .
    For EX: Sort it_tab BY key1 key2
    While Reading i will use only key1 with BINARY SEARCH,Please tell me whether READ statement works?
    Thanks,
    Rathish

    Hello Ratish,
    There isnt any hard and fast rule that you will have to use all the fields on which you sort. The key fields which you may want to use in the READ statement depends on the logic with which you are reading the internal table. As Rob pointed out its better to use all the fields which could make a record unique in the READ statement else it would keep reading only the first occurence of the record.
    Vikranth

  • When I use the search box I would like results to show up in a "NEW" tab but I can't find this setting anywhere... Any solution???

    When I use the search box I would like results to show up in a "NEW" tab but I can't find this setting anywhere... Any solution???

    '''browser.search.openintab''' userset boolean True
    Also in Google search, upper-right-corner settings
    You can always force opening a link into a tab with Ctrl+click or Ctrl+Shift+click
    If you want the same from a bookmark make sure to set
    : '''browser.tabs.loadBookmarksInBackground''' to same value as you have for
    : '''browser.tabs.loadInBackground'''
    The last setting is controlled by Tools > Options > Tabs >
    :: When I click on a link, switch to it immediately,
    which control the difference between Ctrl+click and Ctrl+Shift+click
    Items in boldface''' can be set in about:config
    * '''More information on configuration variables''' available in [http://kb.mozillazine.org/About:config_entries about:config entries] and for users not familiar with the process there is [http://kb.mozillazine.org/About:config about:config] (How to change).
    Reading:
    * http://dmcritchie.mvps.org/firefox/keyboard.htm
    * http://dmcritchie.mvps.org/firefox/tabs_config.htm

  • Are messages sorted by date when you use spotlight search on iphone / ipad?

    When you use spotlight search on an ipad or iphone, and you are searching specifically for text messages,  how are the results sorted?
    it doesnt look like they sort by date modified, or do they?

    i mean Imessages not SMS messages

  • When I use a search engine in Firefox, the links redirect me to some spam, and not the site the search engine found.

    When I use a search engine in Firefox, whether it be google, or Yahoo, the links found by the search engine, re-direct me somewhere else. For instance when I searched for Places to Buy PC Games. www.gamestop.com popped up. When I clicked the link, it took me to some laptop hardware site. But if I type in the url for Gamestop, it takes me to their website. This has happened for several searches, several different links. I tried Internet Explorer thinking it may be a problem with the search engines. But IE is working fine for this.

    This type of behaviour can be caused by malware. Try running several malware scanners. It is best to run several as each will pick up things that the others miss. Some scanners you can try are:
    * [http://www.malwarebytes.org/mbam.php Malwarebytes]
    * [http://www.superantispyware.com/ SUPERAntiSpyware]
    * [http://www.lavasoft.com/products/ad_aware_free.php Ad-Aware]
    * [http://www.microsoft.com/windows/products/winfamily/defender/default.mspx Windows Defender]
    * [http://www.safer-networking.org/en/home/index.html Spybot S&D]
    This site may also be of use - http://deletemalware.blogspot.com/2010/02/remove-google-redirect-virus.html
    If the above malware scanners do not find any malware or can not clear it, you should consider posting in one of these forums for specialized malware removal help:
    * http://forums.spybot.info/
    * http://www.spywarewarrior.com/index.php
    * http://forum.aumha.org/
    * http://www.bleepingcomputer.com/forums/
    * http://www.spywareinfoforum.com/

  • Why does the message '500 internal server error' appear when I use any search engine?

    I am able to type a web address and use the internet successfully but when using ANY search engine I get the '500 internal server error' message. This appears if I type in a word to search '''bold text'''and the result is the error message. I have recently uninstalled rapport and hitman pro. Please help.

    Did you check your security software (firewall)?
    Which security software (firewall) do you have?
    A possible cause is security software (firewall) that blocks or restricts Firefox or the plugin-container process without informing you, possibly after detecting changes (update) to the Firefox program.
    See:
    * [[Server not found]]
    * [[Firewalls]]

  • Please explain how to use binary search in this loop.

    Hi,
    I want to use the binary search in below Read please give me solution....
    LOOP AT it_vbfa_temp ASSIGNING <fs_vbfa_temp>.
          CLEAR is_ekbz1.
          READ TABLE it_ekbz1 INTO is_ekbz1 WITH KEY xblnr = <fs_vbfa_temp>-deliv flag = space.
          IF  sy-subrc = 0.
            w_tabix = sy-tabix.
            is_ekbz1-tknum = <fs_vbfa_temp>-shipno.
            is_ekbz1-flag  = 'X'.
            MODIFY it_ekbz1 FROM is_ekbz1 INDEX w_tabix TRANSPORTING tknum flag.
    ENDLOOP.

    Hi,
    Thanks for the inputs given.. Please find the solution for the same ....
       CLEAR is_ekbz1.
        is_ekbz1-flag = 'X'.
        MODIFY it_ekbz1 FROM is_ekbz1 TRANSPORTING flag WHERE flag IS INITIAL.
        SORT it_ekbz1 BY ebeln xblnr lifnr flag.
      LOOP AT it_vbfa_temp ASSIGNING <fs_vbfa_temp>.
          CLEAR is_ekbz1.
          READ TABLE it_ekbz1 INTO is_ekbz1 WITH KEY xblnr = <fs_vbfa_temp>-deliv flag = 'X' BINARY SEARCH.
          IF  sy-subrc = 0.
            w_tabix = sy-tabix.
            is_ekbz1-tknum = <fs_vbfa_temp>-shipno.
            is_ekbz1-flag  = space.
            MODIFY it_ekbz1 FROM is_ekbz1 INDEX w_tabix TRANSPORTING tknum flag.
      ENDLOOP.
    Regards,
    Srinivas
    Edited by: Srininas on Apr 6, 2010 12:16 PM
    Edited by: Srininas on Apr 6, 2010 12:17 PM

Maybe you are looking for

  • Unique ID's in java - interessting theoretical problem

    Hey all, I'm am trying to generate completely unique id's in java. These ID's should be provable unique within different processes and different systems. The machines IP address should not be assumed unique because, for example, two machine in a diff

  • An exception was caught while scheduling the publication. (FBE60203)

    Hi All, Iam getting below error when  am using publication to send doc to personal email. Please advice me to find out the solution, thanks in adavance... Error Message: ERROR [PublishingService:HandlerPool-124] BusinessObjects_PublicationAdminLog_In

  • No startup sound (I constantly need to restart PRAM)

    Hello, I have a MacBook Pro 2012 mid 13" and some time ago I noticed, that startup sound was gone. I googled a little bit and saw that resetting PRAM should solve the problem. It did. But after a few days startup sound was gone again. So I reseted PR

  • Does anyone has a AM modulator demodulator sample for SSB & DSB?

    please i need an AM modulator demodulator labview application for DSB and SSB for a telecommunication project. i will be thankfull if anyone can help me

  • Java doesn't work on safari

    Since I've installed the latest java version, my browser stop running Java plugin. I cannot access my bank account etc. PS.: I already have unistalled the Java an installed again, twice; I shutted down my computer, I restarted the browser... And, YES