Ordering the Record in FoxPro

Ordering the Record in FoxPro:-

Records in a table are arranged in the same order in which they are entered. This arrangement will not be desirable for all applications, specially when the records are to be accessed according to the values in the specified data field. In a table, data can be kept in a required order using one the two methods.

  1. Sorting
  2. Indexing

In the Sorting, the data is physically copied in the desired order to a new table. Whereas in indexing, a separate file is used to provide a reference as to how the record in the original table should be arranged. Syntax is as follow:

SORT on field name to new file name
SORT on stuname to Stu
use Stu ↵
List ↵
SORT on stuname /d to stu (here d = descending order)

Types of Indexing:-

There are two types of indexing

  1. Compound Indexing
  2. Single Indexing file

The Compound Indexing can store many indexes in a single file. The indexes are represented in the same manner as in the single index. In addition this index is given special name TAG. The compound index file have an extension of .CDX

The Single Index file stores a single index file based on a single index expression or key. A Single file has an extension .IDX

Single Indexing file is used for indexing an field name to new file. Set order to new file name.

Seek command is used to determine if the seek seek command was successful and the function found can be used, the function returns a logical value true or false.

Index an stuname tag kanti
Set Order to kanti
Seek “Kanti”
Disp ↵ displays kanti details

Delete single index file command is used to delete file X.IDX whereas Compound delete command deletes compound index files.

Modifying the table structure is also important as there are times when the structure of a table is required to be satisfied, a new field need to be added, or existing fields needed to be deleted. Existing field values also be changed. A field can be moved from one position to another by dragging the field sector, thereby changing the sequence of the fields in the table. Modi command is used display the table structure and modify it like adding new fields an so on.

What Others Are READING



Leave a Reply

Your email address will not be published. Required fields are marked *