Previous Next

SEEK function
Returns the offset of the file pointer in a text file as an INT64 value. You define a procedure variable to hold the offset value and later position the file to that offset.
Syntax 
 
SEEK ( { INPUT | OUTPUT | name | STREAM-HANDLE handle } )
INPUT
If you specify INPUT, the SEEK function returns the current position of the file pointer in the unnamed input stream.
OUTPUT
If you specify OUTPUT, the SEEK function returns the current position of the file pointer in the unnamed output stream.
name
If you specify SEEK (name), the SEEK function returns the current position of the file pointer in the named input or output stream. The stream must be associated with an open file, or SEEK returns the Unknown value (?).
STREAM-HANDLE handle
If you specify the handle to a stream, the SEEK function returns the current position of the file pointer in the stream. If handle it is not a valid handle to a stream, the AVM generates a run-time error.
Example 
This procedure shows how you can use the SEEK function to access data in an text file. Using SEEK this way allows you to index into a non-indexed file.
 
DEFINE VARIABLE itemno NO-UNDO LIKE Item.ItemNum.
DEFINE VARIABLE itdesc NO-UNDO LIKE Item.ItemName.
DEFINE VARIABLE m-pos  AS INT64 NO-UNDO.
 
SET itemno LABEL
  "Select a record number to position the output file" WITH SIDE-LABELS.
OUTPUT TO test.fil.
FIND Item NO-LOCK WHERE Item.ItemNum = itemno.
IF Item.ItemNum = itemno THEN
  m-pos = SEEK(OUTPUT).
EXPORT Item.ItemNum Item.ItemName.
OUTPUT CLOSE.
 
INPUT FROM test.fil.
SEEK INPUT TO m-pos.
SET itemno itdesc WITH FRAME d2.
INPUT CLOSE.
In the example, you are prompted to select an Item number to position the output file. When a record is found with that Item number, the SEEK function returns the offset into the variable m-pos. The value for m-pos is the current value of the file pointer. The SEEK statement uses the value in m-pos to position the file pointer in the unnamed input stream.
Notes 
*
*
*
*
See also 
DEFINE STREAM statement, INPUT FROM statement, OUTPUT TO statement, SEEK statement, Stream object handle

Previous Next
© 2013 Progress Software Corporation and/or its subsidiaries or affiliates.