Try OpenEdge Now
skip to main content
ABL Reference
ABL Syntax Reference : SEEK function
 

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.
r-seek1.p
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

*The first byte in a file is byte 0.
*You cannot use the SEEK function with the INPUT THROUGH statement, the INPUT-OUTPUT THROUGH statement, or the OUTPUT THROUGH statement. When used with one of these statements, the SEEK function returns the Unknown value (?).
*After you assign the value of the SEEK function to a procedure variable, you can use that value to reposition the file in the event of an error.
*For more information on streams, see the chapter on alternate I/O sources in OpenEdge Development: Programming Interfaces.

See also

DEFINE STREAM statement, INPUT FROM statement, OUTPUT TO statement, SEEK statement, Stream object handle