1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Difference Between FIND FIRST and FOR FIRST

Discussion in 'Development' started by saravanakumar, Jul 30, 2008.

  1. saravanakumar

    saravanakumar New Member

    Hi Everybody,
    Can anyone let me know the exact difference between FIND FIRST and FOR FIRST and where exactly it should be used?

    Thanks in advance. :rolling:
  3. TomBascom

    TomBascom Curmudgeon

    You should rarely, if ever, use either of these. Both of them are misleading and dangerous.

    FOR FIRST is especially nasty -- it finds the record before any specified sorting using whatever index the index selection rules result in. A BY clause will be ignored.

    If you are dealing with an ordered set of data use OPEN QUERY or FOR EACH with an appropriate BY clause.

    If you are dealing with a unique record use FIND without the FIRST but with an appropriately selective WHERE clause that is supported by an index.
  4. saravanakumar

    saravanakumar New Member

    I am worried about the application that i am working on. I could find only FIND FIRST in most of the places. :(

    ...Ya i could get you. Thanks for ur valuable information and quick reply. :yippee:
  5. RKR

    RKR Member

    I do not completely agree with Tom. The by clause is not ignored. Take for instance this simple code example.

    Code (progress):
    2.     FIELD Nummer        AS INTEGER
    3.     FIELD Naam          AS CHARACTER
    4.     INDEX Nummer    IS PRIMARY Nummer
    5.     INDEX Naam      Naam.
    6. CREATE ttTest.
    7. ASSIGN nummer = 1
    8.        naam   = "E".
    9. CREATE ttTest.
    10. ASSIGN nummer = 2
    11.        naam   = "D".
    12. CREATE ttTest.
    13. ASSIGN nummer = 3
    14.        naam   = "C".
    15. CREATE ttTest.
    16. ASSIGN nummer = 4
    17.        naam   = "B".
    18. CREATE ttTest.
    19. ASSIGN nummer = 5
    20.        naam   = "A".
    21. FOR FIRST ttTest BY naam:
    22.     DISP tttest.
    23. END.
    24. FOR FIRST ttTest BY nummer:
    25.     DISP ttTest.
    26. END.
    The main difference however is that the FIND statement is not able to combine multiple indexes. The FOR statement can. When using the for statement you do not have to test if a record is available and if you want to test if a record is not available it is more efficient to use can-find instead of find.
  6. Casper

    Casper ProgressTalk.com Moderator Staff Member

    Well, if the field 'naam' wasn't indexed then the by clause /would/ be ingnored.... So pretty tricky.

  7. TomBascom

    TomBascom Curmudgeon

    Good catch.

    You got me on a "technicality". My point was that the BY is ignored for sorting -- FOR FIRST doesn't sort its result set, it only returns the 1st entry in index order, even if that conflicts with any BY that happens to be specified. You got the expected answer because the naam index was used. And that happened because index selection rules use the BY as a tie-breaker.
  8. TomBascom

    TomBascom Curmudgeon

    The habitual use of FIND FIRST infects far too many Progress applications.

    Unfortunately it is unlikely that you will make any headway stamping it out. Sadly, it is far more likely that you will be told that it is the right way to do things :(
  9. RKR

    RKR Member

    Tom, Casper,

    Completely agree with you this time :lol:. Actually I do not have a habit of using the by phrase on non indexed fields, so I have never stumbled accros this bad habit of the FOR FIRST/LAST. I do agree that it is always a bad habit of using FOR FIRST/FIND FIRST in the first place unless there is no other option available for your requirements.
  10. veenit

    veenit New Member


    The difference is following

    1. For start a loop while find does not.
    2. Find can not use multiple indexes while for can use.

    In case we does not have need to use multiple index and single record always use find otherwise use for.
  11. saravanakumar

    saravanakumar New Member

    Hi Guys,
    ...got the xact difference between FOR FIRST and FIND FIRST as well as its hazards. Tonnes of thanks to u all who participated in this thread.

    Very nice to see these many number of quick replies. It is really amazing to read ur replies and the way u r responding. Very happy to be a member among such a group.

    Thanks a lot to progresstalk.com as well... :party2:

Share This Page