|Navigation: Language Reference > 13 - Built-in Functions >====== RESTORESTATE (restore state of data file) ======|
|RESTORESTATE||Restores a file's savedstate state including the record buffer, file pointer, file sequencing order, and the error state of the system.|
|file||The label of a FILE declaration.|
|savedstate||A LONG numeric variable which represents the value returned by the GETSTATE procedure.|
|restoreflag||A BYTE value that sets whether or not the file's record buffer is to be restored. The default value is FALSE (0), which indicates that the file buffer is not restored.|
RESTORESTATE restores a file's state including the file pointer, file sequencing order, and the current error state of the system. By default, RESTORESTATE does not restore the file's record buffer. Setting the restoreflag to TRUE will restore the state of the file's record buffer.
RESTORESTATE does not change the data stored in a file. If data is added to a file after GETSTATE and before RESTORESTATE, the new record(s) will remain in the data file after the RESTORESTATE.
MyFunction PROCEDURE(FILE MyFile)
! File will be in the same state on exit of this procedure as it was on entry
CurState = GETSTATE(MyFile) !save current state of file
SET(MyFile) !ready to access file
NEXT(MyFile) !read a record
CLEAR(MyFile) !clear record buffer
RESTORESTATE(MyFile,CurState,1) !restore file and buffer to initial state
FREESTATE(MyFile, CurState) !release resources