Sets the position on the first record of a data file according to the specified browse item.
The record is not read.
The number of the current record is modified only when it is returned by
HRecNum. For the functions that handle the current record number (
HDelete,
HRead,
HModify, etc.), the value of this number is not updated: you must use
HRecNum(). For example: not to do:
but
HDelete(Customer, HRecNum())
Values in the browse item are read in ascending order (see Remarks for more details).
Caution: The record loaded in memory is not modified. The HFSQL variables (Customer.Name for example, which means the Name item of Customer file) are not updated.
In most cases,
HFirst sets the position in the data file to loop through the records that match a condition.
HNext is used to position on the next record corresponding to the condition.
Several cases may occur after the call to HFirst:
- a record corresponding to the condition was found: HFound returns True
- the data file is empty or there is no record corresponding to the condition: HOut returns True
Remarks:
- By default, HSeekFirst and HSeekLast are used to perform an exact-match search.
- By default, HFirst performs a generic search.
Values in the browse item are read in ascending order (see
remarks for more details).
Caution: The record loaded in memory is not modified. The HFSQL variables (Customer.Name for example, which means the Name item of Customer file) are not updated.
In most cases,
HFirst is used to set the position in the data file in order to perform a read loop with
HNext.
Several cases may occur after the call to HFirst:
- the data file is empty or no record corresponds to the filter (defined by HFilter): HOut returns True.
- the function tries to lock a record that is already locked in read-only: HErrorLock returns True and HOut returns True.
Access by JDBC: The management of locks is not available for databases accessed by JDBC.
HFirst(Customer, Name)
WHILE HOut() = False
// Process the record
HNext(Customer, Name)
END
Syntax
<Result> = HFirst([<Data file> [, <Search key item>] [, <Options>]])
<Result>: Boolean
- True if the position was set,
- False if an error occurred. This problem can be caused by:
- a positioning problem (empty data file, ...): HFound returns False and HError returns 0.
- an error: HError returns an integer other than 0. HErrorInfo returns more details.
<Data file>: Optional character string
Name of the data file used. If this parameter is an empty string (""), HFirst manipulates the last data file used by the last HFSQL function (function starting with "H").
<Search key item>: Optional character string
Name of key item used to loop through the data file. If this name is not specified, HFirst will use the last browse item used on this data file by the last HFSQL management function (function starting with "H"). If this item does not exist, the best browse item is automatically used.
<Options>: Optional constant
Configures the lock set on the record selected by HFirst: | |
hKeepFilter | The filter set by HFilter will be taken into account, even if the search key is not optimized for the filter. Reminder: HFilter returns the search key optimized for the filter. Caution: In this case, performance issues may arise for large data files.
|
hLockNo | No lock: the record can be read or modified by another application.
|
hLockReadWrite | Lock in read/write: the selected record cannot be read or modified by another application.
|
hLockWrite | Lock in write mode: the selected record can be read by another application but it cannot be modified by another application.
|
hNoRefresh | |
Remarks
Read operation according to a key
HFirst positions on the record with the smallest key value.
The sort order is the one that was specified in the analysis for this key.
If duplicates are found, HFirst sets the position on the first "duplicate" record according to the sequence of record numbers.
Miscellaneous
- The current record number is returned by HRecNum.
- HChangeKey is used to modify the search key while remaining positioned on the current record.
Comparison between HReadFirst and HFirst
HFirst does not read the record: therefore,
HFirst is faster than
HReadFirst.