COMPUTE command (COBOL)
The COMPUTE command assigns the value of an arithmetic expression to a specified reference. The COMPUTE keyword cannot be abbreviated.
>>-COMPUTE--reference--=--expression--;------------------------><
- reference
- A valid Debug Tool COBOL numeric reference.
- expression
- A valid Debug Tool COBOL numeric expression.
Usage notes
- If you are debugging an optimized COBOL program, you can use the COMPUTE command to assign a value to a program variable only if you first enter the SET WARNING OFF command.
- If you are debugging an optimized COBOL program and you specify an expression, you can reference program variables that were not discarded by the optimizer.
- If Debug Tool was started because of a computational condition or an attention interrupt, using an assignment to set a variable might not give expected results. This is due to the uncertainty of variable values within statements as opposed to their values at statement boundaries.
- COMPUTE assigns a value only to a single receiver; unlike COBOL, multiple receiver variables are not supported.
- The COBOL EQUAL keyword is not supported ("=" must be used).
- The COBOL ROUNDED and SIZE ERROR phrases are not supported, so END-COMPUTE is not supported.
- COMPUTE cannot be used to perform a computation with a windowed date field if the expression consists of more than one operand.
- Any expanded date field specified as an operand in the expression is treated as a nondate field.
- The result of the evaluation of the expression is always considered to be a nondate field.
- If the expression consists of a single numeric operand, the COMPUTE will be treated as a MOVE and therefore subject to the same rules as the MOVE command.
- If the DATA parameter of the PLAYBACK ENABLE command is in effect for the current compile unit, the COMPUTE command can be used while you replay recorded statements by using the PLAYBACK commands. The target of the COMPUTE command must be a session variable.
- The value assigned to a variable is always assigned to the storage for that variable. In an optimized program, a variable can be temporarily assigned to a register, and a new value assigned to that variable does not necessarily alter the value used by the program.
Examples
- Assign to variable x the value of a +
6.
COMPUTE x = a + 6;
- Assign to the variable mycode the value of the Debug Tool variable %PATHCODE
+ 1.
COMPUTE mycode = %PATHCODE + 1;
- Assign to variable xx the result of the expression (a
+ e(1)) ⁄ c * 2.
COMPUTE xx = (a + e(1)) ⁄ c * 2;
You can also use table elements in such assignments as shown in the following example.COMPUTE itm-2(1,2) = (a + 10) ⁄ e(2);
Refer to the following topics for more information related to the material discussed in this topic.
- Related references
- MOVE command (COBOL)
- PLAYBACK commands
- SET WARNING command (C, C++, COBOL, and PL/I)