Oracle9i OLAP Services Developer's Guide to the OLAP DML
Release 1 (9.0.1)

Part Number A86720-01
Go To Documentation Library
Go To Product List
Book List
Go To Table Of Contents
Go To Index

Master Index


Go to previous page Go to beginning of chapter Go to next page

Reading Data from Files, 8 of 9

Processing Records Individually

Reading records with varying types of data

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.

Example: Reading different data from the same record

File layout

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

OLAP DML objects used by the program

The following OLAP DML objects are used by the example program.


Program description

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.

Program code

The example program, named DR.PROG4, contains the following code.

variable funit integer
variable varname text
funit = fileopen('dr4.dat' read)
while filenext(funit)
    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
fileclose funit

Reading different records

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.

Related information

For more information, see the following table.

IF you want documentation about . . .  THEN see . . . 


the topic for the command in the OLAP DML Reference 

Go to previous page Go to beginning of chapter Go to next page
Copyright © 1996-2001, Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Go To Product List
Book List
Go To Table Of Contents
Go To Index

Master Index