Sequential Search

i need to extend the below code in order to
search for a Term for example "Computer Graphics"
rather than a single word such as "Graphics"
to run the below code, compile
than at command prompt type:
java DefinitionChecker <filename>
lets say the file contains
Computer Graphics is defined as a pictorial computer output produced on a display screen, plotter, or printer # Computer Graphics is purely delimited by science # Mobile Agents are defined as autonomous, intelligent programs that move through a network, searching for and interacting with services on the user's behalf. #
# Computer Graphicsis defined as science # Graphics is as ahmad # Mobile Agent can be defined as an agent that transports itself and its execution state through the net #
Assuming the user enters "Mobile Agent"
results should be :
From File XYZ.txt
Search results:
1) Mobile Agent can be defined as an agent that transports itself and its execution state through the net.
2) Mobile Agents are defined as autonomous, intelligent programs that move through a network, searching for and interacting with services on the user's behalf.
From File TravelPLan.txt
Search Results:
1) ..
2)..
import java.util.Vector;
import java.io.*;
public class DefinitionChecker{
String keyword;
String[] token1 = new String[]{" is "," are "," was "," be "," can be "};
String[] token2 = new String[]{" defined "," described "," delimited "};
String[] token3 = new String[]{" as "," by "};
String sentences[];
public static void main(String[] args){
if (args.length < 1){
System.out.println("USAGE : DefintionChecker keyword file");
DefinitionChecker dc = new DefinitionChecker(args);
public DefinitionChecker(String[] args){
try{
sentences = getArrayFromFile(new File(args[1]));
}catch(IOException ioe){
System.out.println(ioe);
keyword = args[0].toLowerCase();
for (int i = 0; i < sentences.length; i++){
int pos = 0;
//System.out.println("Checking : " + sentences);
if (sentences[i].toLowerCase().indexOf(keyword) > -1 && containsToken(token2,sentences[i].toLowerCase(),0) > -1){
if ((pos = containsToken(token1,sentences[i].toLowerCase(),pos)) != -1){
if ((pos = containsToken(token2,sentences[i].toLowerCase(),pos)) != -1){
if ((pos = containsToken(token3,sentences[i].toLowerCase(),pos)) != -1){
System.out.println("\t\tMATCH : " + sentences[i]);
}else{
//System.out.println("\t\t" + sentences[i] + " has no token3.");
}else{
//System.out.println("\t\t" + sentences[i] + " has no token2.");
}else{
//System.out.println("\t\t" + sentences[i] + " has no token1.");
}else{
//System.out.println("\t\t" + sentences[i] + " has no keyword or has no token2.");
private int containsToken(String[] tokens, String s, int pos){
int tPosition = -1;
for (int i = 0; i < tokens.length && tPosition == -1; i++){
tPosition = s.indexOf(tokens[i],pos);
return tPosition;
private String[] getArrayFromFile(File f) throws IOException{
FileReader reader = new FileReader(f);
Vector sentences = new Vector();
char[] cbuf = new char[1];
String delimiter = "#";
String sentence = "";
String c = "";
while (reader.read(cbuf) != -1){
c = new String(cbuf);
if (c.equals(delimiter)){
sentences.add(sentence);
sentence = "";
}else{
sentence += c;
String[] sentenceArray = new String[sentences.size()];
sentenceArray = (String[])sentences.toArray(sentenceArray);
return sentenceArray;

Rather than using the exhaustive code currently commented out, can't you just use the keywords AS the token in your tokenizer? I am assuming the keywords need to be matched "in sequence". (So "Computer Graphics" will not match against "Graphics Computer")
The hash (#) seems to be the "end of sentence" delimiter. So, create a StringTokenizer using the keyword (args[0]) as the delimiter.
I am assuming this is for a Uni assignment or something, so I won't worry about performance issues.
Read the whole file into a String (not generally good practice, but for the sake of a Uni assigment who cares!). Use your tokenizer to parse the string.
The tokenizer will delimit the string on the basis of the keyword. For each result the tokenizer gives you, truncate the result at the point of the hash (#). This should give you a string starting with your keyword, and ending prior to the hash.
EG:
import java.util.*;
String keyword = args[0];
String fileContents; // Put the contents of your file into this
StringTokenizer st = new StringTokenizer(fileContents, keyword);
List results = new LinkedList();
String result = null;
while(st.hasMoreTokens) {
// Get the actual result
result = st.nextToken();
// truncate the result at the hash
result = result.substring(0, result.indexOf("#");
//Add the original keyword because the tokenizer will have removed it
result = keyword + result;
// Add to the list of results
results.add(result);
No guarantees on the "compilability" of this, but you should get the idea.
Now.. how about them Duke Dollars? :)

Similar Messages

  • Sequential search then update record

    Hi guys,
    I have an issue with the following tables. I am just a beginner using oracle. LRS_ID is the unique field. BMP is Beginning Mile Point and EMP is End Mile Point. Table 1 shows a sample of how my data is.
    Table 1
    LRS_ID            BMP     EMP
    014001101100     0.00     1.19
    014001101100     1.19     1.28
    014301101100     2.65     6.11
    014301101100     8.42     11.21
    014301101100     11.21     13.67
    014301101100     17.02     17.44
    014501102100     0.00     0.51
    014501102100     2.10     4.96
    014601102100     0.00     7.13
    014601102100     7.13     7.46
    014601102100     7.46     9.82
    014601102100     9.82     9.91
    014601102100     9.91     10.56
    014601102100     10.56     13.47
    014601102100     14.15     17.42
    Table 2
    LRS_ID             BMP     EMP
    014001101100     0.00     1.28
    014301101100     2.65     6.11
    014301101100     8.42     13.67
    014301101100     17.02     17.44
    014501102100     0.00     0.51
    014501102100     2.10     4.96
    014601102100     0.00     13.47
    014601102100     14.15     17.42Table 2 shows what I need to do. For each unique LRS_IDs I need to go through the BMP and EMP for each row. If the EMP for the first record is equal to the BMP of the second record keep going until there is a change. If there is no change I should only have ONE BMP and ONE EMP for that LRS_ID. BMP should be the lowest Milepoint and EMP should be the highest.
    If there is a discrepancy I need to keep that as a unique record. However, I do need to get the min and max for the ones that matched upto that point.
    I am really confused as to how I can go about solving this using SQL.
    Any guidance or logic will be very much appreciated

    SQL> select * from tab_1 order by 1,2,3;
    LRS_ID                      BMP        EMP
    014001101100                  0       1.19
    014001101100               1.19       1.28
    014301101100               2.65       6.11
    014301101100               8.42      11.21
    014301101100              11.21      13.67
    014301101100              17.02      17.44
    014501102100                  0        .51
    014501102100                2.1       4.96
    014601102100                  0       7.13
    014601102100               7.13       7.46
    014601102100               7.46       9.82
    014601102100               9.82       9.91
    014601102100               9.91      10.56
    014601102100              10.56      13.47
    014601102100              14.15      17.42
    15 rows selected.
    SQL> select lrs_id, min(bmp) bmp, max(emp) emp from (
      2  select lrs_id, bmp, emp, diff, sum(diff) over(partition by lrs_id order by bmp
      3  rows between current row and unbounded following) sm
      4  from (
      5  select lrs_id, bmp, emp,
      6  (lead(bmp,1,emp) over(partition by lrs_id order by bmp) - emp) diff
      7  from tab_1
      8  )
      9  )
    10  group by lrs_id, sm
    11  order by 1,2
    12  /
    LRS_ID                      BMP        EMP
    014001101100                  0       1.28
    014301101100               2.65       6.11
    014301101100               8.42      13.67
    014301101100              17.02      17.44
    014501102100                  0        .51
    014501102100                2.1       4.96
    014601102100                  0      13.47
    014601102100              14.15      17.42
    8 rows selected.Rgds.

  • Linear search and binary search

    Hi
    can any one tell me what is linear and binary search in detail.
    and what is the difference between them .
    which one is useful in coding.
    Thanks&Regards,
    S.GangiReddy.

    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 value 16.
    Linear search use sequential search means each and every reord will be searched to find. so it is slow.
    Binary search uses logrim for searching. Itab MUST be sorted on KEY fields fro binary search. so it is very fast.
    The search takes place as follows for the individual table types :
    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.
    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. The addition BINARY SEARCH can be specified for sorted tables, but has no effect.
    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.
    Binary search must be preffered over linear sarch.
    Hope this is helpful, Do reward.

  • Search Algorithms help

    Hi, im a new to java, so dont know much. Can anypne help me with wrtting a basic prog to preform a Sequential Search or Binary Search, with the output to be entered by the user eiter using JPane or command line.
    thanks.

    Hi there,
    For the Sequential search you need just a for loop.
    e.g. for a String array
    public class serc
      public static void main(String[] args)
        String[] A={"hi","there","how","are","you"};
        String search="how";  //We are searching "how"
        for(int i=0;i<A.length;i++)
          if (A.equals(search))
    System.out.println(A[i]);
    break;
    For the binary sarch try this. Modify it according to your needs.
    public class serc
      public static void main(String[] args)
        int[] A=new int[]{1,2,3,4,5,6}; //The array has to be sorted
        int search=5;  //We are searching "5"
        int found=ser.search(A,search,0,A.length);
        System.out.println(found);   //if found it will be printed it's position
       found=ser.search(A,3,0,A.length);
        System.out.println(found);   //if found it will be printed it's position
    class ser
      public static int search(int[] a,int s,int start,int end)
        int m=(int)((start+end)/2);
        if (a[m]==s)
          return m;
        else if(a[m]>s)
          return ser.search(a,s,0,m);
        else
          return ser.search(a,s,m,end);
    }If you need explanation, just ask for it.
    Hope this helped

  • 6110 navigator music player track search problems

    I recently "downgraded" from a N73 ME to a 6110 Navigator, due to the GPS. Eventhough 6110 is newer, for me it is a downgrade (except for the GPS), because of the inferior camera, smaller screen, music player, horrible battery life etc...
    Anyways, this post is about the music player. I'm used to search tracks by name in N73, but I can't do that with 6110. Only Artist, Album and Genre can be searched (but even that is a very simple sequential search from the beginning of the name, N73 filters text from any part of the name). Are there any workarounds for track searching (like in N73)?
    Only thing I can think of right now is to change either the Album or Genre field to have the track name (which is not a good way to resolve it)
    I find the built-in player to have better sound quality than few of the 3rd party players I tried, therefore I'm interested in getting the track search feature in the built-in player.
    Thanks.
    [P.S : Firmware v 03.58, RM-122]
    Message Edited by optiplexfx on 20-Sep-2008 04:22 AM
    Message Edited by optiplexfx on 20-Sep-2008 04:24 AM

    The soluction for me
    1- Delete the Music Library files stored at memory card using X-plore or another file manager (the file path in my phone was E:\Private\100012a5\DBS_101FE031_mcv4.mpd);
    Note: \Private folder can only be seen when the PC SUITE is not being used.  I found it using cable and using transfer data setting on phone.
    2- Remove the memory card;
    3- Open the Music Player and refresh the Music Library;
    4- Delete the Library file at the phone's memory (C:\Private\100012a5\DBS_101FE031_mcv4.mpd);
    5- Put the memory card back and transfer the music files using the PC SUITE;
    6- Go to the Galery, select TRACKS and the files shall be found;
    7- Open the Music Player and refresh the Library;

  • Hard disk failing?

    Hello everybody,
    My computer started having problems this morning.
    I have a Macbook Pro Unibody from 2008 running Lion (the first unibody that came out) with 320 gb hard disk and 4gb RAM.
    Yesterday, everything was doing just fine, I put on some music before going to bed and set up an app called iTaf to stop iTunes automatically after an hour. I didn't ask it to shut the computer down though.
    When I woke up this morning, my computer was stuck on a grey screen and was completely unresponsive. I could'nt do anything else but force shut it down with the power button.
    After rebooting, my computer was extremely sluggish and was pretty much unresponsive. I force shut it down a couple of times (it wouldn't shut down properly), but the problem was remaining.
    I tried starting it up in safe boot mode, but after 2 hours, my computer still hadn't booted and the loading circle kept spinning.
    Now, everytime I turn my computer on, I still have the safe boot mode screen (grey screen with the circle spinning and the loading bar filling a little bit, then disappearing and the circle keeps spinning, without anything else happening) and it won't reboot like it did before I started safe boot mode.
    I ran Disk Utility through Internet recovery (I don't have a Super Drive anymore) and it says that everything's ok with my hard disk. Mackintosh HD is not mounted though and locked (I have Filevault enabled). When I try to unlock the drive, it won't accept my password (I have an azerty keyboard and the layout was set to US. I changed it back to French, but it still won't accept my password, probably because it contains the letter " à " and the french layout doesn't kick in.).
    So I tried running single user mode, and when I type in the fsck -fy command, this is what I get:
    CoreStorageGroup: :complete IORequest - error 0xe00002ca detected for LVG "Macintosh HD" (E97F03A2-D03C-48C0-85D2-B470539CC780), pv F0B573D5-41D5-42E9-8B1D-7E432E4C99F6, near LV byte
    disk1: I/O error.
    Invalid record count
    (4, 279)
    ** The volume Mackintosh HD could not be verified completely.
    /dev/rdisk1 (hfs) EXITED WITH SIGNAL 8
    What is strange though, is that I can still run my computer under guest mode and surf the internet...
    I don't understand what's going on, can anyone help me?
    If the hard disk is failing, do you think I could still recover some important files I added this week and had no time to back up?

    As an FYI, the only product on the market for drive/system testing on CoreStorage components on a "live" system to the best of my knowledge is Scannerz:
    http://www.scsc-online.com
    Don't go out and buy it, because that's likely not your problem. What the system is telling you is that you have an INDEXING problem.
    Consider the following: You go to a library and you want to find a book on a topic. How do you do it? Do you start at the first shelf you see and then sequentially search from shelf to shelf to shelf, possibly from hundreds of thousand (or even millions) of books until you find the book? Of course not. You go to the libraries catalog, look it up and then go to the right shelf. Hard drives use index files the same way. When a file is requested, the drive looks at its index, then moves directly to the sectors containing the information.
    Now, suppose you go to the library and you go to look up a book in the index files, and someone has stolen some of them (or if they're on a computer, they've deleted them...same thing). There's no information available at all. There's no way to find out where the books associated with the index files are. This is essentially what's happened to your hard drive. Some of the index files are corrupt, and in your case the index files that are missing are associated with the OS actually in the process of  loading, hence the failure to boot.
    This problem can be caused by the following:
    1. Some of the sectors containing the startup information are corrupt (essentially a drive failure).
    2. An application you have somehow or another managed to overwrite the indexing or startup files with information that doesn't make sense.
    Like I said, Scannerz is, to the best of my knowledge the only application that can currently test CoreStorage components on a "live" system which would be needed in your case because you're using fully encrypted volumes, but it's of little value to you at this point. Even if you mounted and booted from an external drive and ran Scannerz on it and it confirmed that the sectors in the startup section of the drive were bad, all that would do is identify the source of the problem for you, not correct it. There is no utility on Earth than can properly recover information from a completely damaged sector (although some claim they can ... they're lying) any more than you can recover information from a paper page that someone set on fire and burned to ash.
    The only option for you that MIGHT work would be Disk Warrior which can HOPEFULLY rebuild and remap the index files. Be forewarned of the following though:
    1. It can't perform miracles. It may or may not be able to re-generate the index files for you.
    2. It's a fairly old utility and how much they've kept up with changing technology, file system changes, etc. is unknown to me. Core Storage is NEW technology and I have no way of knowing how something like Disk Warrior will handle it. I would like to think they'll get around to dealing with it in the near future if they haven't already.
    Here's a link to their website:
    http://www.alsoft.com/diskwarrior
    I hope this helps you make your decision, and good luck!

  • Query in select statment

    Hi ,
        what is the difference between,select single and
    select upto one row .
    In a select statment .
    Thanks ,
    shankar.

    According to SAP Performance course the SELECT UP TO 1 ROWS is faster than SELECT SINGLE because you are not
    using all the primary key fields.
    select single is a construct designed to read database records with primary key. In the absence of the primary key,
    it might end up doing a sequential search, whereas the select up to 1 rows may assume that there is no primary key
    supplied and will try to find most suitable index.
    The best way to find out is through sql trace or runtime analysis.
    Use "select up to 1 rows" only if you are sure that all the records returned will have the same value for the field(s)
    you are interested in. If not, you will be reading only the first record which matches the criteria, but may be the
    second or the third record has the value you are looking for.
    The System test result showed that the variant Single * takes less time than Up to 1 rows as there is an additional
    level for COUNT STOP KEY for SELECT ENDSELECT UP TO 1 ROWS.
    The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause
    If this results in multiple records then only the first one will be returned and therefore may not be unique.
    Mainly: to read data from
    The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that
    are defined by the WHERE clause, applies any aggregate, ordering or grouping functions to them and then returns
    the first record of the result set.
    Mainly: to check if entries exist.
    You can refer to the below link..
    http://www.sap-img.com/abap/difference-between-select-single-and-select-upto-one-rows.htm

  • I need help on this program..

    import java.util.*;
    public class D3
    private static int[] z = new int[100000];
    private static int first=z[0];
    private static int last=z[n-1];
    private static int n=100000;
    public static void main(String args[])
    Scanner input=new Scanner(System.in);
    for(int i=0;i<z.length;i++)
    z=2*i;
    int seqSearch(z;50000;n); //method call 4 key where key=mid
    int binSearch(z;first;last;50000);
    int seqSearch(z;35467;n); //method call 4 key where key in the left half
    int binSearch(z;first;last;35467);
    int seqSearch(z;89703;n); //method call 4 key where key in the right half
    int binSearch(z;first;last;89703);
    public int seqSearch(int z[];int key;int n)
    long start = System.currentTimeMillis();
    int count=0;
    int ans=-1;
    for(int i=0;i<n;i++)
    if z=key
    count++
    {ans=i
    break;}
    return ans;
    long elapsed = System.currentTimeMillis() - start;
    System.out.print("Execution Time:" + elapsed);
    System.out.print("# of Basic Operations:" + count);
    public int binSearch(int z[];int first;int last;int key)
    long start = System.currentTimeMillis();
    int count=0;
    if(last><first){
    count++;
    index=-1;
    else
    count++;
    int mid=(first+last)/2
    if(ket=z[mid]{
    index=mid;
    else
    if(key><z[mid]){
    index = binSearch(z[];first;mid-1;key);
    else
    index=binSearch(z[];mid+1;last;key);
    return index;
    long elapsed = System.currentTimeMillis() - start;
    System.out.print("Execution Time:" + elapsed);
    System.out.print("# of Basic Operations:" + count);
    if anyone could please tell me whats wrong with my code i'd be greatful...the program is supposed to perform binary and sequential search on a sorted array of 100000 numbers.once on an item in the middle of the array once on the right side of it and once on the left side...i also need to count the number of basic operations for the same number in both sequential and binary to see whats better.and i need to check the time...i think the method call is wrong,not sure though...plz i need help.its not compiling and i dont know why..

    Just add new messages to a thread you've already created. Don't create a new thread each time.
    Anyway, look. This is wrong:int seqSearch(z;50000;n); //method call 4 key where key=midfor two reasons. The first is that leading "int"; it doesn't mean anything here. "int" is used to declare an integer variable, but you're not declaring a variable here, you're invoking a method. The second problem is that you're using semicolons to separate arguments in the method call, but actually commas are correct. You probably want something more like this:
    int result;
    result = seqSearch(z, 50000, n);  //method call 4 key where key=mid.
    Some more problems with your code: you're calling non-static methods in a static context (the main method is static and seqSearch isn't). You're also using "n" before you declare it, which is probably a problem.
    And this makes no sense:z=2*i;because you've declared z to be an array; you can't use the multiplication operator on an array. It's not clear really what you're trying to accomplish there.
    Here's what I want you to do. Take your code and completely remove the binSearch method. Just rip it out. Then in your main() method, take out all references to the binSearch method, and all references except for the first one of the seqSearch method. Fix the things I mentioned above.
    Then try to compile what you have. It won't compile. You will get error messages. That's OK. Just fix them and move on. If you don't understand an error message, ask on these forums (DON'T CROSSPOST), quoting the full error message and the relevant lines of code.
    After a couple hours, you'll fix the syntactical bugs, and your program will compile. Then you'll find that it compiles but the program doesn't work right. That's also OK. This is how computer programming works. It's part of the process. Don't panic. At that point, you can start trying to fix the program so it does what it's supposed to. Eventually you'll get it to work.
    Then, and only then add more invocations of the seqSearch method. They won't all work, probably. You'll find more bugs. That's OK. Just repeat the process of fixing them.
    When you've fixed those bugs, then, and only then, add the binSearch method. Repeat the process of fixing syntax and hunting down and fixing bugs.
    Then your program will work.

  • IF STATEMMENT is not working completely

    I can not get my if statement to complete the false condition and it should display "Login Successful" if it matches an item in the array and should clear the fields and display "Invalid. Try Again" if not successful.
    Can someone help me with this?
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    public class PasswordApplet extends Applet implements ActionListener
    //Declaring variables
    String id;
    String password;
    boolean success;
    //Construct variables
    String idArray[] = {"tuetken", "jones", "smith", "white", "black", "johnson"};
    String passwordArray[] = {"redfox", "reddog", "bravo", "alpha", "tango",};
    //Create components for applet
    Label headerLabel = new Label("Please type your ID and Password");
    Label idLabel = new Label("ID:");
    TextField idField = new TextField(8);
    Label passwordLabel = new Label("Password:");
    TextField passwordField = new TextField(8);
    Button loginButton = new Button("Login");
    public void init()
    //Set color, layout, and add components
    setBackground(Color.blue);
    setLayout(new FlowLayout(FlowLayout.LEFT,50,30));
    add(headerLabel);
    //headerLabel.setText("Login Successful");
    add(idLabel);
    add(idField);
    idField.requestFocus();
    add(passwordLabel);
         add(passwordField);
         passwordField.setEchoChar('*');
    add(loginButton);
    loginButton.addActionListener(this);
    public void actionPerformed(ActionEvent e)
         id = idField.getText();//reads the text
         password = passwordField.getText();//reads the text
         success = true;
         //Sequential search
         for (int i = 0; i < idArray.length; i++)
         if((idArray.compareTo(id)==0) &&
         (passwordArray[i].compareTo(password)==0))
         //success = true;
                   if(success == true){
                        headerLabel.setText("Login Successful");
                        repaint();
                        }else if(success == false){
                             headerLabel.setText("Invalid. Try Again.");
                             repaint();}
                             idField = null;
                             passwordField = null;
                             idField.requestFocus();

    Is this what you were asking me to do?
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    public class PasswordApplet extends Applet implements ActionListener
       //Declaring variables
       String id;
       String password;
       boolean success;
       //Construct variables
       String idArray[] = {"tuetken", "jones", "smith", "white", "black", "johnson"};
       String passwordArray[] = {"redfox", "reddog", "bravo", "alpha", "tango",};
       //Create components for applet
       Label headerLabel = new Label("Please type your ID and Password");
       Label idLabel = new Label("ID:");
          TextField idField = new TextField(8);
       Label passwordLabel = new Label("Password:");
          TextField passwordField = new TextField(8);
       Button loginButton = new Button("Login");
       public void init()
       //Set color, layout, and add components
       setBackground(Color.blue);
       setLayout(new FlowLayout(FlowLayout.LEFT,50,30));
       add(headerLabel);
          //headerLabel.setText("Login Successful");
       add(idLabel);
          add(idField);
          idField.requestFocus();
       add(passwordLabel);
            add(passwordField);
            passwordField.setEchoChar('*');
       add(loginButton);
             loginButton.addActionListener(this);
       public void actionPerformed(ActionEvent e)
            id = idField.getText();//reads the text
            password = passwordField.getText();//reads the text
            success = true;
            //Sequential search
            for (int i = 0; i < idArray.length; i++)
            if((idArray.compareTo(id)==0) &&
         (passwordArray[i].compareTo(password)==0))
         success = true;
                   if(success == true){
                        headerLabel.setText("Login Successful");
                        repaint();
                        }else if(success == false){
                             headerLabel.setText("Invalid. Try Again.");
                             repaint();}
                             idField = null;
                             passwordField = null;
                             idField.requestFocus();

  • Internal table and work area

    Hi,
           can anybody explain the concepts of Internal table and work area.Thanks in advance.

    hai,
    This may help u.
    WORKAREA is a structure that can hold only one record at a time. It is a collection of fields. We use workarea as we cannot directly read from a table. In order to interact with a table we need workarea. When a Select Statement is executed on a table then the first record is read and put into the header of the table and from there put into the header or the workarea(of the same structure as that of the table)of the internal table and then transferred top the body of the internal table or directly displayed from the workarea.
    Each row in a table is a record and each column is a field.
    While adding or retrieving records to / from internal table we have to keep the record temporarily.
    The area where this record is kept is called as work area for the internal table. The area must have the same structure as that of internal table. An internal table consists of a body and an optional header line.
    Header line is a implicit work area for the internal table. It depends on how the internal table is declared that the itab will have the header line or not.
    e.g.
    data: begin of itab occurs 10,
    ab type c,
    cd type i,
    end of itab. " this table will have the header line.
    data: wa_itab like itab. " explicit work area for itab
    data: itab1 like itab occurs 10. " table is without header line.
    Internal tables are used for storing records which are obtained as a result when we use select statement on database. internal tables are run time entities and doesn't occupy any memory. they are dynamic.
    internal tables are of types.
    1. internal tables with header line. [header and body]
    2. internal tables with out header line. [only body]
    Workarea is the concept which is mainly useful when working with internal tables with out header line.
    at any point of time we can access only one record through header of a internal table. every thing should be done [inserting,modifying, reading ] through header only.
    ex: data: itab like standard table of mara with header line.
    for internal tables with out header line we will create a work area [explicit header] as type of table for storing data into internal table.
    ex: data: itab like mara,
    wa like mara.
    more about internal table types:
    Standard table:
    The key access to a standard table uses a sequential search. The time required for an access is linearly dependent on the number of entries in the internal table.
    You should usually access a standard table with index operations.
    Sorted table:
    The table is always stored internally sorted by its key. Key access to a sorted table can therefore use a binary search. If the key is not unique, the entry with the lowest index is accessed. The time required for an access is logarithmically dependent on the number of entries in the internal table.
    Index accesses to sorted tables are also allowed. You should usually access a sorted table using its key.
    Hash table:
    The table is internally managed with a hash procedure. All the entries must have a unique key. The time required for a key access is constant, that is it does not depend on the number of entries in the internal table.
    You cannot access a hash table with an index. Accesses must use generic key operations (SORT, LOOP, etc.).
    Hashed tables
    This is the most appropriate type for any table where the main operation is key access. You cannot access a hashed table using its index.
    The response time for key access remains constant, regardless of the number of table entries. Like database tables, hashed tables always
    have a unique key. Hashed tables are useful if you want to construct and use an internal table which resembles a database table or for
    processing large amounts of data.
    TYPES VECTOR TYPE HASHED TABLE OF I WITH UNIQUE KEY TABLE LINE.
    TYPES: BEGIN OF LINE,
    COLUMN1 TYPE I,
    COLUMN2 TYPE I,
    COLUMN3 TYPE I,
    END OF LINE.
    DATA ITAB TYPE HASHED TABLE OF SPFLI
    WITH UNIQUE KEY CARRID CONNID.
    with regards,
    B.Sowjanya,
    reward points if helpful.

  • Select and join

    Hi
    I want to know when is good to do join between 2 tables
    or to do select and loop and in the loop select single
    When it good to use for all entries
    Thanks
    have a nice day

    Hi
    JOIN is faster to fetch the data from database tables provided they have some connecting fields in both tables
    for all entries
    The WHERE clause of the SELECT statement has a special variant that allows you to derive conditions from the lines and columns of an internal table:
    SELECT ... FOR ALL ENTRIES IN <itab> WHERE <cond> ...
    <cond> may be formulated as described above. If you specify a field of the internal table <itab> as an operand in a condition, you address all lines of the internal table. The comparison is then performed for each line of the internal table. For each line, the system selects the lines from the database table that satisfy the condition. The result set of the SELECT statement is the union of the individual selections for each line of the internal table. Duplicate lines are automatically eliminated from the result set. If <itab> is empty, the addition FOR ALL ENTRIES is disregarded, and all entries are read.
    The internal table <itab> must have a structured line type, and each field that occurs in the condition <cond> must be compatible with the column of the database with which it is compared. Do not use the operators LIKE, BETWEEN, and IN in comparisons using internal table fields. You may not use the ORDER BY clause in the same SELECT statement.
    You can use the option FOR ALL ENTRIES to replace nested select loops by operations on internal tables. This can significantly improve the performance for large sets of selected data.
    Select single and Upto 1 rows
    Difference Between Select Single and Select UpTo One Rows
    According to SAP Performance course the SELECT UP TO 1 ROWS is faster than SELECT SINGLE because you are not using all the primary key fields.
    select single is a construct designed to read database records with primary key. In the absence of the primary key, it might end up doing a sequential search, whereas the select up to 1 rows may assume that there is no primary key supplied and will try to find most suitable index.
    The best way to find out is through sql trace or runtime analysis.
    Use "select up to 1 rows" only if you are sure that all the records returned will have the same value for the field(s) you are interested in. If not, you will be reading only the first record which matches the criteria, but may be the second or the third record has the value you are looking for.
    The System test result showed that the variant Single * takes less time than Up to 1 rows as there is an additional level for COUNT STOP KEY for SELECT ENDSELECT UP TO 1 ROWS.
    The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause If this results in multiple records then only the first one will be returned and therefore may not be unique.
    Mainly: to read data from
    The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause, applies any aggregate, ordering or grouping functions to them and then returns the first record of the result set.
    Mainly: to check if entries exist.
    Reward points for useful Answers
    Regards
    Anji

  • Select single and select

    hi everybody
    what is the exact difference between select single vbeln  and select vbeln
    In what situations i should use these select single vbeln or select vbeln
    regards
    hridhayanjili.

    Hai
    Go through the following Document
    According to SAP Performance course the SELECT UP TO 1 ROWS is faster than SELECT SINGLE because you are not
    using all the primary key fields.
    select single is a construct designed to read database records with primary key. In the absence of the primary key,
    it might end up doing a sequential search, whereas the select up to 1 rows may assume that there is no primary key
    supplied and will try to find most suitable index.
    The best way to find out is through sql trace or runtime analysis.
    Use "select up to 1 rows" only if you are sure that all the records returned will have the same value for the field(s)
    you are interested in. If not, you will be reading only the first record which matches the criteria, but may be the
    second or the third record has the value you are looking for.
    The System test result showed that the variant Single * takes less time than Up to 1 rows as there is an additional
    level for COUNT STOP KEY for SELECT ENDSELECT UP TO 1 ROWS.
    The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause
    If this results in multiple records then only the first one will be returned and therefore may not be unique.
    Mainly: to read data from
    The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that
    are defined by the WHERE clause, applies any aggregate, ordering or grouping functions to them and then returns
    the first record of the result set.
    Mainly: to check if entries exist.
    You can refer to the below link..
    http://www.sap-img.com/abap/difference-between-select-single-and-select-upto-one-rows.htm
    Regards
    Sreeni

  • Select Single * and Select upto one row

    Hi all,
    Can anybody tell me what is difference between Select single * and select upto one row?
    And which one is better?
    Thanks in advance.......

    According to SAP Performance course the SELECT UP TO 1 ROWS is faster than SELECT SINGLE because you are not using all the primary key fields.
    select single is a construct designed to read database records with primary key. In the absence of the primary key, it might end up doing a sequential search, whereas the select up to 1 rows may assume that there is no primary key supplied and will try to find most suitable index.
    The best way to find out is through sql trace or runtime analysis.
    Use "select up to 1 rows" only if you are sure that all the records returned will have the same value for the field(s) you are interested in. If not, you will be reading only the first record which matches the criteria, but may be the second or the third record has the value you are looking for.
    The System test result showed that the variant Single * takes less time than Up to 1 rows as there is an additional level for COUNT STOP KEY for SELECT ENDSELECT UP TO 1 ROWS.
    The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause If this results in multiple records then only the first one will be returned and therefore may not be unique.
    Mainly: to read data from
    The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause, applies any aggregate, ordering or grouping functions to them and then returns the first record of the result set.
    Mainly: to check if entries exist.
    Select Single is the best one compared to UPto one rows.
    Select Single will get the first record from the table which satisfies the given condition.So it will interact once with the database.
    UTO 1 rows will get the list of the records for the given match and iwll show the first record from the list.So it will take time to get the record.
    SELECT SINGLE VBELN from VBAK
    where MATNR = '1M20'.
    ---Thjis will get the first matched record and will display the record
    SELECT VBELN from VBAK
    where MATNR = '1M20' upto 1 rows.
    ---Thjis will get the list of matched records and will display the first record
    The Major difference between Select Single and Select UPTO 1 rows is The Usage Of Buffer for each.
    Select Single will search for all the satisfied data and bring all that data into Buffer and later it will give to that data to the program.
    Select UPTO 1 Rows will end the search after getting the 1st satisfied record and gives that record to the program.
    Thus Select Single will take much processing time when compare with Select UPTO 1 rows.
    Also
    check these threads..
    Difference between Select Single and Selct upto 1 row
    Difference between Select Single and Select upto 1 row
    Difference between select single and select upto one row
    Difference between 'select single *' and 'select upto 1 rows'
    difference between select single and select up to 1 rows
    regards,
    srinivas
    <b>*reward for useful answers*</b>

  • Select single and select upto 1 rows

    Hi
    What is the difference between select single and select upto 1 rows
    Performance wise which one is the best
    Regards,
    Maya

    Hi,
    Difference Between Select Single and Select UpTo One Rows
    According to SAP Performance course the SELECT UP TO 1 ROWS is faster than SELECT SINGLE because you are not using all the primary key fields.
    select single is a construct designed to read database records with primary key. In the absence of the primary key, it might end up doing a sequential search, whereas the select up to 1 rows may assume that there is no primary key supplied and will try to find most suitable index.
    The best way to find out is through sql trace or runtime analysis.
    Use "select up to 1 rows" only if you are sure that all the records returned will have the same value for the field(s) you are interested in. If not, you will be reading only the first record which matches the criteria, but may be the second or the third record has the value you are looking for.
    The System test result showed that the variant Single * takes less time than Up to 1 rows as there is an additional level for COUNT STOP KEY for SELECT ENDSELECT UP TO 1 ROWS.
    The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause If this results in multiple records then only the first one will be returned and therefore may not be unique.
    Mainly: to read data from
    The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause, applies any aggregate, ordering or grouping functions to them and then returns the first record of the result set.
    Mainly: to check if entries exist.
    reward points if useful
    regards,
    ANJI

  • Select single and select upto

    what is the difference of select single and select upto statements

    HI,
    SELECT UP TO 1 ROWS is faster than SELECT SINGLE because you are not using all the primary key fields.
    select single is a construct designed to read database records with primary key. In the absence of the primary key, it might end up doing a sequential search, whereas the select up to 1 rows may assume that there is no primary key supplied and will try to find most suitable index.
    The best way to find out is through sql trace or runtime analysis.
    Use "select up to 1 rows" only if you are sure that all the records returned will have the same value for the field(s) you are interested in. If not, you will be reading only the first record which matches the criteria, but may be the second or the third record has the value you are looking for.
    The System test result showed that the variant Single * takes less time than Up to 1 rows as there is an additional level for COUNT STOP KEY for SELECT ENDSELECT UP TO 1 ROWS.
    The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause If this results in multiple records then only the first one will be returned and therefore may not be unique.
    Mainly: to read data from
    The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause, applies any aggregate, ordering or grouping functions to them and then returns the first record of the result set.
    Mainly: to check if entries exist.

Maybe you are looking for