SKIP

SKIP

Move the record pointer to a new position

Syntax

      SKIP [<nRecords>] [ALIAS <idAlias> | <nWorkArea>]

Arguments

<nRecords> is a numeric expression specifying the number of records to move the record pointer from the current position. A positive value moves the record pointer forward and a negative value moves the record pointer backward.

ALIAS <idAlias>|<nWorkArea> specifies the alias name as a literal identifier or the work area as a numeric expression.

SKIP specified with no arguments moves the record pointer forward one record.

Description

SKIP moves the record pointer to a new position relative to the current position in the current work area and within the current filter, if there is one. SKIP is generally used for operations, such as reporting, that need to go to the next record in a database file.

If the alias clause is specified, the pointer can be moved in another work area without SELECTing that work area. SKIP can move either forward or backward. If there is no active index, SKIP moves the record pointer relative to the current position in the target database file. If there is an active index, SKIP moves the pointer relative to the current position in the index instead of the database file.

Attempting to SKIP forward beyond the end of file positions the record pointer at LASTREC() + 1, and EOF() returns true (.T.). Attempting to SKIP backward beyond the beginning of file moves the pointer to the first record, and BOF() returns true (.T.).

In a network environment, any record movement command, including SKIP, makes changes to the current work area visible to other applications if the current file is shared and the changes were made during an RLOCK(). To force an update to become visible without changing the current record position, use SKIP 0. If, however, the changes were made during an FLOCK(), visibility is not guaranteed until the lock is released, a COMMIT is performed, or the file is closed. Refer to the “Network Programming” chapter for more information.

Examples

      .  This example uses SKIP with various arguments and shows their
         results:

      USE Customers NEW
      SKIP
      ? RECNO()                  // Result: 2
      SKIP 10
      ? RECNO()                  // Result: 12
      SKIP -5
      ? RECNO()                  // Result: 7

      .  This example moves the record pointer in a remote work area:

      USE Customers NEW
      USE Invoices NEW
      SKIP ALIAS Customers

      .  This example prints a report using SKIP to move the record
         pointer sequentially through the Customer database file:

      LOCAL nLine := 99
      USE Customers NEW
      SET PRINTER ON
      DO WHILE !EOF()
         IF nLine > 55
            EJECT
            nLine := 1
         ENDIF
            ? Customer, Address, City, State, Zip
            nLine++
            SKIP
         ENDDO
      SET PRINTER OFF
      CLOSE Customers

Seealso

BOF(), COMMIT, DBSKIP(), EOF(), GO, LOCATE, RECNO(), SEEK

Advertisements

SELECT

SELECT

Change the current work area

Syntax

      SELECT <xnWorkArea> | <idAlias>

Arguments

<xnWorkArea> is the work area number between 0 and 250 inclusive. This argument is an extended expression and can be specified either as a literal number or as a numeric expression enclosed in parentheses.

<idAlias> is the name of an existing work area to SELECT if there is a database file open in that area.

Description

SELECT is a database command that changes work areas. CA-Clipper supports 250 work areas, with each work area a logical handle to an open database file and all of its attributes. You can refer to work areas with SELECT by number or by alias. The alias of a work area is automatically assigned when a database file is USEd in that work area or by using the ALIAS clause.

Work area 0 refers to the first empty or next available work area. Using this, you can SELECT 0 and USE <xcDatabase> as a method of opening database files.

Notes

. Aliased expressions: Aliased expressions are a much more powerful method of selecting new work areas than the SELECT command. Instead of SELECTing a work area, and then performing an operation for that work area, you can apply an alias to an expression that performs the operation. This is done by specifying the alias of the remote work area and the expression enclosed in parentheses. For example, to access the value of EOF() in an unselected work area, you would normally execute a series of statements like the following:

            SELECT Remote
            ? EOF()
            SELECT Main

Using the aliased expression form, these statements become:

            ? Remote->(EOF())

. USE…NEW: Instead of using SELECT0 and USE <xcDatabase> to open a database file in a new work area, the preferred method is to USE <xcDatabase> NEW.

Examples

      .  This example opens a series of database files by SELECTing
         each work area by number then USEing each database file in that
         work area:

         SELECT 1
         USE Customer
         SELECT 2
         USE Invoices
         SELECT 3
         USE Parts
         SELECT Customer

      .  A better method is to open each database in the next available
         work area by specifying the NEW clause on the USE command line.
          In this example USE...NEW is employed instead of SELECT 0 and
         then USE:

         USE Customer NEW
         USE Invoices NEW

         SELECT Customer

      .  This code fragment changes work areas while saving the current
         work area name to a variable using the SELECT() function.  After
         executing an operation for the new work area, the original work
         area is restored:

         nLastArea := SELECT()
         USE Newfile NEW
         //
         <statements>...
         //
         SELECT (nLastArea)

Seealso

ALIAS(), EOF(), SELECT(), SET INDEX, USE, USED()

SEEK

Search an order for a specified key value

Syntax

      SEEK <expSearch> [SOFTSEEK]

Arguments

<expSearch> is an expression to match with an order key value.

SOFTSEEK causes the record pointer to be moved to the next record with a higher key value after a failed order search. Default behavior moves the record pointer to EOF() after a failed order search.

Description

SEEK is a database command that searches the controlling order from the first or last key value (depending on whether the LAST keyword is specified) and proceeds until a match is found or there is a key value greater than <expSearch>. If there is a match, the record pointer is positioned to the identity found in the order. If SOFTSEEK is OFF (the default) and SEEK does not find a match, the record pointer is positioned to LASTREC() + 1, EOF() returns true (.T.), and FOUND() returns false (.F.).

SOFTSEEK enables a method of searching an order and returning a record even if there is no match for a specified key.

When SOFTSEEK is ON and a match for a SEEK is not found, the record pointer is set to the next record in the order with a higher key value than the SEEK argument. Records are not visible because SET FILTER and/or SET DELETED are skipped when searching for the next higher key value. If there is no record with a higher key value, the record pointer is positioned at LASTREC() + 1, EOF() returns true (.T.), and FOUND() returns false (.F.). FOUND() returns true (.T.) only if the record is actually found. FOUND() never returns true (.T.) for a relative find.

When SOFTSEEK is OFF and a SEEK is unsuccessful, the record pointer is positioned at LASTREC() + 1, EOF() returns true (.T.), and FOUND() returns false (.F.).

SEEK with the SOFTSEEK clause is, effectively, the same as performing SET SOFTSEEK and then SEEK in earlier versions of Clipper except that it does not change the global setting of SOFTSEEK.

Examples

      .  The following example searches for "Doe" using the SEEK
         command:

      USE Customer NEW
      SET ORDER TO Customer
      ? SET( _SET_SOFTSEEK )      // (.F.)
      SEEK "Doe"
      ? SET( _SET_SOFTSEEK )      // Still (.F.)
      IF FOUND()
         .
         . < statements >
         .
      ENDIF

      .  The following example performs a soft seek for "Doe" using
         SOFTSEEK clause of the SEEK command:

      USE Customer NEW
      SET ORDER TO Customer
      ? SET( _SET_SOFTSEEK )      // (.F.)
      SEEK "Doe" SOFTSEEK
      ? SET( _SET_SOFTSEEK )      // Still (.F.)
      IF !FOUND()
         ? Customer->Name         // Returns next logical name after "Doe"
      ENDIF

Seealso

DBSEEK(), DBSETINDEX(), DBSETORDER(), EOF(), SET INDEX

LOCATE

LOCATE

Search sequentially for a record matching a condition

Syntax

      LOCATE [<scope>] FOR <lCondition>
             [WHILE <lCondition>]

Arguments

<scope> is the portion of the current database file in which to perform the LOCATE. The default scope is ALL records.

FOR <lCondition> specifies the next record to LOCATE within the given scope.

WHILE <lCondition> specifies the set of records meeting the condition from the current record until the condition fails.

Description

LOCATE is a database command that searches for the first record in the current work area that matches the specified conditions and scope. When you first execute a LOCATE, it searches from the beginning record of the scope for the first matching record in the current work area. It terminates when a match is found or the end of the LOCATE scope is reached. If it is successful, the matching record becomes the current record and FOUND() returns true (.T.). If it is unsuccessful, FOUND() returns false (.F.) and the positioning of the record pointer depends on the controlling scope of the LOCATE.

Each work area can have its own LOCATE condition. The condition remains active until you execute another LOCATE command in that work area or the application terminates.

LOCATE works with CONTINUE. Once a LOCATE has been issued, you can resume the search from the current record pointer position with CONTINUE. There are, however, some exceptions. See note below.

Notes

. CONTINUE: Both the <scope> and the WHILE condition apply only to the initial LOCATE and are not operational for any subsequent CONTINUE commands. To continue a pending LOCATE with a scope or WHILE condition, use SKIP then LOCATE REST WHILE <lCondition> instead of CONTINUE.

Examples

      .  These examples show typical LOCATEs:
      USE Sales INDEX Salesman
      LOCATE FOR Branch = "200"
      ? FOUND(), EOF(), RECNO()         // Result: .T. .F. 5
      LOCATE FOR Branch = "5000"
      ? FOUND(), EOF(), RECNO()         // Result: .F. .T. 85
      .  This example shows a LOCATE with a WHILE condition that is
         continued by using LOCATE REST:
      SEEK "Bill"
      LOCATE FOR Branch = "200" WHILE Salesman = "Bill"
      DO WHILE FOUND()
         ? Branch, Salesman
         SKIP
         LOCATE REST FOR Branch = "200" WHILE ;
                  Salesman = "Bill"
      ENDDO

Seealso

CONTINUE, EOF(), FOUND(), SEEK, SET FILTER

FIND

FIND*

Search an index for a specified key value

Syntax

      FIND <xcSearchString>

Arguments

<xcSearchString> is part or all of the index key of a record to search for, and can be specified either as a literal string or as a character expression enclosed in parentheses. If an expression is specified instead of a literal string, FIND operates the same as SEEK.

Description

FIND is a database command that searches an index for the first key matching the specified character string and positions the record pointer to the corresponding record.

If SOFTSEEK is OFF and FIND does not find a record, the record pointer is positioned to LASTREC() + 1, EOF() returns true (.T.), and FOUND() returns false (.F.).

If SOFTSEEK is ON, the record pointer is positioned to the record with the first key value greater than the search argument and FOUND() returns false (.F.). In this case, EOF() returns true (.T.) only if there are no keys in the index greater than the search argument. FIND is a compatibility command and therefore not recommended. Its usage is superseded entirely by the SEEK command.

Examples

      .  These examples show simple FIND results:
      USE Sales INDEX Branch NEW
      FIND ("500")
      ? FOUND(), EOF(), RECNO()         // Result: .F. .T. 85
      FIND "200"
      ? FOUND(), EOF(), RECNO()         // Result: .T. .F. 5
      FIND "100"
      ? FOUND(), EOF(), RECNO()         // Result: .T. .F. 1

Seealso

EOF(), FOUND(), RECNO(), SEEK, SET INDEX, SET ORDER

CONTINUE

CONTINUE

Resume a pending LOCATE

Syntax

      CONTINUE

Description

CONTINUE is a database command that searches from the current record position for the next record meeting the most recent LOCATE condition executed in the current work area. It terminates when a match is found or end of file is encountered. If CONTINUE is successful, the matching record becomes the current record and FOUND() returns true (.T.); if unsuccessful, FOUND() returns false (.F.).

Each work area may have an active LOCATE condition. In Harbour, a LOCATE condition remains pending until a new LOCATE condition is specified. No other commands release the condition.

Notes

. Scope and WHILE condition: Note that the scope and WHILE condition of the initial LOCATE are ignored; only the FOR condition is used with CONTINUE. If you are using a LOCATE with a WHILE condition and want to continue the search for a matching record, use SKIP and then repeat the original LOCATE statement adding REST as the scope.

Examples

      .  This example scans records in Sales.dbf for a particular
         salesman and displays a running total sales amounts:
      LOCAL nRunTotal := 0
      USE Sales NEW
      LOCATE FOR Sales->Salesman = "1002"
      DO WHILE FOUND()
         ? Sales->Salesname, nRunTotal += Sales->Amount
         CONTINUE
      ENDDO
      .  This example demonstrates how to continue if the pending
      LOCATE scope contains a WHILE condition:
      LOCAL nRunTotal := 0
      USE Sales INDEX Salesman NEW
      SEEK "1002"
      LOCATE REST WHILE Sales->Salesman = "1002";
            FOR Sales->Amount > 5000
      DO WHILE FOUND()
         ? Sales->Salesname, nRunTotal += Sales->Amount
         SKIP
         LOCATE REST WHILE Sales->Salesman = "1002";
            FOR Sales->Amount > 5000
      ENDDO

Seealso

EOF(), FOUND(), LOCATE, SEEK