Oracle9i OLAP Developer's Guide to the OLAP DML Release 2 (9.2) Part Number A95298-01 |
|
Developing Programs, 4 of 12
Variables that hold the data in your analytic workspaces are permanent variables. These variables persist from one OLAP session to another. However, you might not need to save variables that your programs use to hold processing information while they manipulate data. So that you do not clutter your analytic workspaces with unnecessary variables, you can define temporary and local variables:
Local variables have no dimensions, so you cannot use them for storing dimensioned data. Because they exist only for the duration of the program in which they are defined, you cannot store information in a local variable in one program and then use that variable in another program. If you must store dimensioned data, or use information in more than one program, then define a temporary variable instead.
The purpose of most OLAP DML programs is to manipulate data. Depending on your programming style and the requirements of your application, you might use either of the following approaches:
Most applications combine these approaches, using permanent variables and user-defined functions when they are appropriate. In general, modular programs are considered to be easier to read, debug, and maintain.
You define temporary variables with the TEMP
keyword in the DEFINE
command, as in the following example.
DEFINE total.sales DECIMAL TEMP
Defining temporary variables for use in programs helps you avoid cluttering your analytic workspace with temporary data, but it still adds objects to your analytic workspace. For most simple applications, the addition of a few temporary objects is not a problem. However, in complex applications that require many programs, the number of temporary objects can sometimes get very large, and this can affect the application's performance.
Once defined, a temporary variable will exist for the remainder of a user's session unless it is deleted. Be sure to delete the temporary variable as part of the cleanup of your program, or create it on the condition that it does not already exist, so that it can be rerun during a session without causing an error.
You must specify local variables at the beginning of your program, before any executable commands. You specify a local variable with the VARIABLE
command, which has the following syntax.
VARIABLEname
datatype
The name
argument specifies the name of the variable. To minimize confusion or problems, you should avoid using the same name for both an analytic workspace variable and a local variable. When both an analytic workspace variable and a local variable have the same name, then the local variable usually takes precedence. However, in a few commands and functions that operate on workspace objects (for example, the OBJ function), the defined variable takes precedence.
The datatype
argument specifies the data type of the local variable. For more information on data types, see "Data Types".
The program named west.rpt
, listed below, includes definitions for two local variables named data
and rpt.month
.
DEFINE west.rpt PROGRAM LD Produce report for Western Sales District PROGRAM VARIABLE data TEXT VARIABLE rpt.month TEXT LIMIT month TO LAST 3 . . .
|
Copyright © 2001, 2002 Oracle Corporation. All Rights Reserved. |
|