Oracle9i OLAP Developer's Guide to the OLAP DML Release 2 (9.2) Part Number A95298-01 |
|
Reading Data from Files, 8 of 9
Your data files do not always have the same type of data in every record. You might find that you need different field descriptions and different target objects for each record, or you might have two or more distinct types of records mixed together in a single file. You might even have to decide what to do with the data in a record based on the contents of one or more of its fields.
The FILENEXT
function and the FILEVIEW
command allow you to retrieve one record at a time from a file and look at its data one or more times. FILENEXT
is a Boolean function, which reads a record from the data file. It returns YES
when it finds a record and NO
when it reaches the end of the file. The record read by FILENEXT
is then available to process with the FILEVIEW
command.
Typically, FILENEXT
is used as the condition of a WHILE
command, so that the data-reading program continues reading until it reaches the end of the file and finds no more records. Within the WHILE
loop, the FILEVIEW
command is used one or more times to process data from any field in the current record. Often the operation of a FILEVIEW
command depends on the data processed by a previous command in the WHILE
loop.
In the data shown in the following example, the second field of each record contains the name of the target variable for the data in the last field.
CEREALS DOL VS100 US JUN96 5000000 CEREALS LBS VS100 US JUN96 4800000 CEREALS CASE VS100 US JUN96 180000 CEREALS DOL VS100 BOS JUN96 62500 CEREALS LBS VS100 BOS JUN96 62830 CEREALS CASES VS100 BOS JUN96 2750 CEREALS DOL VS100 CHI JUN96 75290 CEREALS LBS VS100 CHI JUN96 73000 CEREALS CASES VS100 CHI JUN96 2700 CEREALS DOL VS100 LASF JUN96 143070 CEREALS LBS VS100 LASF JUN96 150500 CEREALS CASES VS100 LASF JUN96 NA
The following OLAP DML objects are used by the example program.
DEFINE dol VARIABLE DECIMAL <month item market> DEFINE lbs VARIABLE INTEGER <month item market> DEFINE cases VARIABLE INTEGER <month item market>
The dr.prog4
program tests records against criterion before getting values. In the program, the first FILEVIEW
command gets the name of the variable and stores it in a local variable named varname
. The second FILEVIEW
command gets the value and assigns it to the object specified in varname
.
The example program, named dr.prog4
, contains the following code.
VARIABLE funit INTEGER VARIABLE varname TEXT funit = FILEOPEN('olapfiles/dr4.dat' READ) WHILE FILENEXT(funit) DO FILEVIEW funit COLUMN 13 WIDTH 12 varname FILEVIEW funit COLUMN 25 WIDTH 12 item - COLUMN 37 WIDTH 6 market - COLUMN 43 WIDTH 5 month - COLUMN 48 WIDTH 10 &varname DOEND FILECLOSE funit
You might want to process only some of the records in a file, based on some criterion in the record itself. You can use one FILEVIEW
command to check a field for an appropriate value and, if it is found, then you can process the rest of the record with a second FILEVIEW
command.
When the record does not meet the criterion for processing, you can save it in another file using the FILEPUT
command. FILEPUT
with the FROM
keyword writes the last record read by FILENEXT
directly to the designated output file. You can also use a FILEPUT
command in the error section of your program to keep track of any records that could not be processed because of errors.
Before you use FILEPUT
in your data-reading program, you must open a second file in write mode. At the end of the program, you must close it.
|
Copyright © 2001, 2002 Oracle Corporation. All Rights Reserved. |
|