Previous Page | Next Page

Functions and CALL Routines

FREWIND Function



Positions the file pointer to the start of the file.
Category: External Files

Syntax
Argument
Details
Examples
See Also

Syntax

FREWIND(file-id)


Argument

file-id

is a numeric variable that specifies the identifier that was assigned when the file was opened, generally by the FOPEN function.


Details

FREWIND returns 0 if the operation was successful, [ne]0 if it was not successful. FREWIND has no effect on a file opened with sequential access.


Examples

This example assigns the fileref MYFILE to an external file. Then it opens the file and reads the records until the end of the file is reached. The FREWIND function then repositions the pointer to the beginning of the file. The first record is read again and stored in the File Data Buffer (FDB). The first token is retrieved and stored in the macro variable VAL:

%let filrf=myfile;
%let rc=%sysfunc(filename(filrf,
   physical-filename));
%let fid=%sysfunc(fopen(&filrf));
%let rc=0;
%do %while (&rc ne -1);
   /* Read a record. */
   %let rc=%sysfunc(fread(&fid));
%end;
   /* Reposition pointer to beginning of file. */
%if &rc = -1 %then
  %do;
    %let rc=%sysfunc(frewind(&fid));
       /* Read first record. */
    %let rc=%sysfunc(fread(&fid));
       /* Read first token  */
       /* into macro variable VAL. */
    %let rc=%sysfunc(fget(&fid,val));
    %put val=&val;
  %end;
%else
  %put Error on fread=%sysfunc(sysmsg());
%let rc=%sysfunc(fclose(&fid));
%let rc=%sysfunc(filename(filrf));


See Also

Functions:

FCLOSE Function

FGET Function

FILENAME Function

FOPEN Function

FREAD Function

MOPEN Function

SYSMSG Function

Previous Page | Next Page | Top of Page