COMPUTE

In this section:

How to:

Reference:

The COMPUTE command enables you to:


Top of page

x
Syntax: How to Use the COMPUTE Command

The syntax of the COMPUTE command is:

[COMPUTE] 
target_variable[/datatype [DFC cc YRT yy] [missing]][= expression];
.
.
.
   missing:  [MISSING {ON|OFF} [NEEDS] [SOME|ALL] [DATA]]

where:

COMPUTE

Is an optional keyword. It is required if the preceding command can take an optional semicolon terminator, but was coded without one. In all other situations it is unnecessary.

When the COMPUTE keyword is required, and there is a sequence of COMPUTE commands, the keyword needs to be specified only once for the sequence, for the first command in the sequence.

target_variable

Is the name of the variable which is being created and/or to which a value is being assigned. A variable name must start with a letter and can only contain letters, numbers and underscores ( _ ).

datatype

Is included in order to create a new variable. If you are creating a simple variable, you can specify all built-in formats and edit options (except for TX) as described for the Master File FORMAT attribute in the Describing Data With WebFOCUS Language manual. If you are creating an object, you can specify a class. You must specify a data type when you create a new variable. You can only specify the data type of a variable once, and you cannot redefine the data type of an existing variable.

DFC cc

Specifies a default century that will be used to interpret any dates with unspecified centuries in expressions assigned to this variable. cc is a two-digit number indicating the century (for example, 19 would indicate the twentieth century). If this is not specified, it defaults to 19.

Specifying DFC cc is optional if the data type is a built-in format. It is not specified if the data type is a class, as it is relevant only for scalar variables.

For information about working with cross-century dates, see Unique FOCUS Topics on the WebFOCUS Documentation CD.

YRT yy

Specifies a default threshold year for applying the default century identified in DFC cc. yy is a two-digit number indicating the year. If this is not specified, it defaults to 00.

When the year of the date being evaluated is less than the threshold year, the century of the date being evaluated defaults to the century defined in DFC cc plus one. When the year is equal to or greater than the threshold year, the century of the date being evaluated defaults to the century defined in DFC cc.

Specifying YRT yy is optional if the data type is a built-in format. It is not specified if the data type is a class, as it is relevant only for scalar variables.

For information about working with cross-century dates, see Unique FOCUS Topics on the WebFOCUS Documentation CD.

missing

Is used to allow or disallow null values. This is optional if the data type is a built-in format. It is not specified if the data type is a class, as it is relevant only for scalar variables.

MISSING

If the MISSING syntax is omitted, the default value of the variable is zero for numeric variables and a space for character and date and time variables. If it is included, its default value is null.

ON

Sets the default value to null.

OFF

Sets the default value to zero or a space.

NEEDS

Is an optional keyword that clarifies the meaning of the command for a reader.

SOME

Indicates that for the target variable to have a value, some (at least one) of the variables in the expression must have a value. If all of the variables in the expression are null, the target variable will be null. This is the default.

ALL

Indicates that for the target variable to have a value, all the variables in the expression must have values. If any of the variables in the expression are null, the target variable will be null.

DATA

Is an optional keyword that clarifies the meaning of the command for a reader.

=

Is optional when COMPUTE is used solely to establish format. The equal sign is required when expression is used.

expression

Is any standard Maintain expression, as defined in Expressions Reference. Each expression must be terminated with a semicolon (;). When creating a new variable using a class data type, you must omit expression.



Example: Moving the COMPUTE Keyword

You can place an expression on the same line as the COMPUTE keyword, or on a different line, so that

COMPUTE
TempEmp_ID/A9 = '000000000';

is the same as:

COMPUTE TempEmp_ID/A9 = '000000000';


Example: Multi-Statement COMPUTE Commands

You can type a COMPUTE command over as many lines as you need. You can also specify a series of assignments as long as each expression is ended with a semicolon. For example:

COMPUTE TempEmp_ID/A9 = '000000000';
   TempLast_Name/A15 ;
   TempFirst_Name/A10;


Example: Combining Several Statements Into One Line

Several expressions can be placed on one line as long as each expression ends with a semicolon. The following shows two COMPUTE expressions on one line and a third COMPUTE on the next line. The first computes a five percent raise and the second increases education hours by eight. The third concatenates two name fields into one field:

COMPUTE Raise/D12.2=Curr_Sal*1.05; Ed_Hrs=Ed_Hrs+8;
Name/A25 = First_Name || Last_Name;

Top of page

x
Reference: Usage Notes for COMPUTE

Top of page

x
Reference: Commands Related to COMPUTE

Top of page

x
Using COMPUTE to Call Functions

When you call a function as a separate statement (that is, outside of a larger expression), if the preceding command can take an optional semicolon terminator, but was coded without one, you must call the function in a COMPUTE or PERFORM command. You can use PERFORM for Maintain functions only, though not for Maintain functions that return a value. For example, in the following source code, the NEXT command is not terminated with a semicolon, so the function that follows it must be called in a COMPUTE command:

NEXT CustID INTO CustStack
COMPUTE VerifyCustID();

However, in all other situations, you can call functions directly, without a COMPUTE command. For example, in the following source code, the NEXT command is terminated with a semicolon, so the function that follows it can be called without a COMPUTE command:

NEXT CustID INTO CustStack;
VerifyCustID();

For more information about terminating commands with semicolons, see Terminating Command Syntax.


WebFOCUS