SEEK Statement
Positions the file pointer by a byte offset relative to the start, end or current position, in a file previously opened for sequential access.
Syntax
SEEK seqfile-var{,offset {,relto }} {SETTING setting-var} {ON ERROR statement(s)} [THEN statement(s) | ELSE statement(s) ]
Syntax Elements
seqfile-varis the name of a variable containing a sequential file reference (assigned via an OPENSEQ statement).
offsetA numeric value to be added to the file position specified by relto to give a new current file position. If not specified defaults to zero.
reltoOne of the following literals:
S or 0Relative to the start of the file.
C or 1Relative to the current position.
E or 2Relative to the end of the file.
If not specified, defaults to the start of the file.
setting-varThe name of a variable to which the return status is assigned. See Operation for details of the possible values for this variable.
statement(s)A sequence of one or more valid DataBasic statements, either separated by semicolons, or contained on separate lines and followed by an END statement.
Operation
The following details circumstances under which the different clauses are executed and the values returned in setting-var:
Clause Executed |
Reason |
setting-var |
STATUS() Value |
---|---|---|---|
THEN |
Seek successful |
Current position |
0 |
ELSE |
Invalid offset (before start of file or item) |
2418 |
3 |
|
File or item does not exist |
2420 |
206 |
ON ERROR |
File or item opened, but not for sequential access (not opened with OPENSEQ) |
B45 |
12 |
|
File or item not open |
B12 |
12 |
|
General file error |
Error number |
Error number |
Note
-
If an error occurs but there is no ON ERROR clause, the DataBasic Debugger will be entered with error B53 as well as the setting-var value.
-
The final column gives the values returned by the STATUS function if this is used instead of a SETTING clause.
Comments
If the combination of the relto and offset parameters results in a position that is beyond the end of the file or item, the next write operation will append the appropriate number of NULL (X'00') characters to allow the data to be written at the specified position.
Example
OPENSEQ "/usr/pauls/qa4" TO SF1 THEN SEEK SF1,128 THEN NULL READBLK DATA FROM SF1,20 THEN PRINT DATA END CLOSESEQ SF1
This program opens the host file /usr/pauls/qa4 and saves a reference to the open file in variable SF1. If the file exists, the program then seeks to a position 128 characters from the start of the file, and reads and displays the next 20 characters. Finally, the file is closed.
See Also
OPENSEQ statement, CLOSESEQ statement, READSEQ statement, READBLK statement, WRITESEQ statement, WRITEBLK statement, WEOFSEQ statement, DELETESEQ statement.