Oracle9i OLAP Services Developer's Guide to the OLAP DML Release 1 (9.0.1) Part Number A86720-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('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.
For more information, see the following table.
IF you want documentation about . . . | THEN see . . . |
---|---|
FILEPUT, FILENEXT, and FILEVIEW, |
the topic for the command in the OLAP DML Reference |
|
Copyright © 1996-2001, Oracle Corporation. All Rights Reserved. |
|