PreviousNextIndex

SEEK statement

Positions the file pointer to a user-defined offset in a text file. This statement does not require you to close and reopen the file.

Syntax

SEEK  
  { INPUT | OUTPUT | STREAM stream | STREAM-HANDLE handle }  
  TO { expression | END } 

INPUT
OUTPUT
STREAM stream
STREAM-HANDLE handle
TO expression
END
Example

Since text file formats differ on each machine, the SEEK function does not necessarily return a number that is meaningful to anyone, but it is meaningful to the SEEK statement. With the exception of SEEK to 0 or SEEK TO END, any address used in the SEEK statement is only guaranteed to behave consistently if the address was previously derived from the SEEK function. Therefore, an expression such as SEEK TO SEEK (INPUT) -n might work differently on different operating systems. Record delimiters must be new-lines on UNIX, and carriage-return/linefeed pairs on all others.

r-seek.p
/* This procedure seeks to the end-of-file, collects the seek address, and 
   writes a record. The record is subsequently retrieved using the SEEK 
   statement on the stashed seek address. */ 
DEFINE VARIABLE savepos AS INT64     NO-UNDO. 
DEFINE VARIABLE c       AS CHARACTER NO-UNDO FORMAT "x(20)". 
OUTPUT TO seek.out APPEND NO-ECHO. 
savepos = SEEK(OUTPUT). 
PUT UNFORMATTED "abcdefg" SKIP. 
OUTPUT CLOSE. 
INPUT FROM seek.out NO-ECHO. 
SEEK INPUT TO savepos. 
SET c. 
DISPLAY c. 
INPUT CLOSE. 

Notes
See also

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


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex