In this section: |
How to: |
Reference: |
The COMPUTE command enables you to:
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:
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.
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 ( _ ).
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.
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.
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.
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.
If the MISSING syntax is omitted, the default value of the variable is zero (0) for numeric variables and a space for character and date and time variables. If it is included, its default value is null.
Sets the default value to null.
Sets the default value to zero (0) or a space.
Is an optional keyword that clarifies the meaning of the command for a reader.
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.
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.
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.
Is any standard Maintain Data expression, as defined in Expressions Reference. Each expression must end with a semicolon (;). When creating a new variable using a class data type, you must omit expression.
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';
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;
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;
There are two different ways these fields can be defined. The first uses the notation:
COMPUTE target_variable/format =;
Because there is no expression after the equal sign (=), the field and its format is made known, but nothing else happens. If this style is used for a field in a form, the field appears on the form without a default value. Because COMPUTE is used solely to establish format, the equal sign is optional and the following syntax is also correct:
COMPUTE target_variable/format;
The second method of defining a user-defined field can be used when an initial value is desired. The syntax is:
COMPUTE target_variable/format = expression;
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 Data functions only, though not for Maintain Data functions that return a value. For example, in the following source code, the NEXT command does not end 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 ends 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 a semicolon (;), see Terminating a Command's Syntax.
Instead of using WINFORM SET to dynamically change the property of an object, compute a variable to a value, and assign that variable to the property of the object. When the variable is evaluated, the property of the object is dynamically set.
For example, instead of issuing the following WINFORM SET command:
WINFORM SET FORM.OBJECT.FOCUS TO HERE;
Issue the following COMPUTE command and assign the variable to the FOCUS property of the object.
COMPUTE VAR/I1=1;
where:
Is the name of the variable used in the dynamic set.
Note: In App Studio Maintain Data, assign the variable to the FOCUS property of the desired object.