Oracle® OLAP DML Reference 10g Release 2 (10.2) Part Number B14346-02 |
|
|
View PDF |
The FILENEXT function makes a record available for processing by the FILEVIEW command. It returns YES
when it was able to read a record and NO
when it reached the end of the file.
Return Value
BOOLEAN
Syntax
FILENEXT(fileunit)
Arguments
An INTEGER
value that is assigned to a file that is opened for reading in a previous call to the FILEOPEN function or by the OUTFILE command.
Notes
Opening and Closing Files
Before you can get records from a file with FILENEXT, use the FILEOPEN function to open the file for reading (READ mode). When you are finished, close the file with a FILECLOSE statement.
Processing Data
After reading a record with FILENEXT, use a FILEVIEW statement to process the record. FILEVIEW processes input data and assigns the data to analytic workspace objects or local variables according to a description of each field. You can call FILEVIEW more than once for continued processing of the same record. To process another record, call FILENEXT again.
Automatic Looping
When all the records are being processed in essentially the same way, the FILEREAD command is easier to use because it loops over the records in a file automatically.
Writing Records
To write selected records to an output file, see the FILEPUT command.
Record Numbers
Use the RECNO function to get the current record number for any file that is opened for read-only access.
Reading Binary and Text Files
When you did not specify BINARY for the file when you opened it, FILENEXT reads data up to and including the next newline character. When you specified BINARY for the file when you opened it, you must use FILESET to set LSIZE to the appropriate record length before using the FILENEXT function. Then, FILENEXT reads data one record at a time.
Examples
Example 15-1 Program That Uses FILENEXT
Suppose you receive monthly sales data in a file with the following record layout.
Column Width Format Data
1 1 Text Division code
2 10 Text District name
12 10 Text Product name
30 4 Packed binary Sales in dollars
34 4 Packed binary Sales in units
You want to process records only for your division, whose code is A. The following program excerpt opens the file, reads the lines of the file, determines if the data is for division A and, if so, reads the sales data, then closes the file. The file name is given as an argument on the statement line after the program name.
VARIABLE fil.unit INTEGER . . . fil.unit = FILEOPEN(arg(1) READ) LIMIT month TO &arg(2) WHILE FILENEXT(fil.unit) DO FILEVIEW fil.unit WIDTH 1 rectype IF rectype EQ 'A' THEN FILEVIEW fil.unit COLUMN 2 WIDTH 10 district - WIDTH 10 product - COLUMN 30 WIDTH 4 BINARY sales - WIDTH 4 BINARY UNITS DOEND FILECLOSE fil.unit