Arithmetic expressions are used as operands of certain conditional and arithmetic statements. An arithmetic expression can consist of the following -

  • An identifier described as a numeric elementary item.
  • A numeric literal.
  • The figurative constant ZERO.
  • Combination of identifiers and literals (defined as above items 1, 2 or 3) separated by arithmetic operators.

Any arithmetic expression can be preceded by a unary operator. Identifiers and literals appear in arithmetic expressions must represent either numeric elementary items or numeric literals.

If an exponential expression is evaluated, the result is always the positive number. For example, the square root of 9 - 9 ** 0.5 is evaluated as +3 and -3. COBOL for Windows always returns +3.

If the value of an expression to be raised to a power is zero, the exponent must have a value greater than zero. Otherwise, the size error condition exists. In any case no real number exists as the result of an evaluation, the size error condition exists.

Arithmetic Operators -

Five arithmetic operators and two unary arithmetic operators can be used in arithmetic expressions.

Binary Operators -

Binary operatorMeaning
+ Addition
- Subtraction
* Multiplication
/ Division
** Exponentiation

Unary Operators -

Unary operatorMeaning
+ Multiplication by +1
- Multiplication by -1

Parentheses can be used in arithmetic expressions to specify the order in which elements are to be evaluated. Expressions within parentheses are evaluated first. When expressions are contained within nested parentheses, evaluation proceeds from the least inclusive to the most inclusive set.

Arithmetic with date fields -

Arithmetic operations that include a date field are restricted to -

  • Adding a nondate to a date field.
  • Subtracting a nondate from a date field.
  • Subtracting a date field from a compatible date field.

Date field operands are compatible if they have the same date format except for the year part. The following operations are not allowed -

  • Any operation between incompatible dates.
  • Adding two date fields.
  • Subtracting a date field from a nondate.
  • Unary minus applied to a date field.
  • Division, exponentiation, or multiplication of or by a date field.
  • Arithmetic expressions that specify a year-last date field.
  • Arithmetic statements that specify a year-last date field, except as a receiving data item when the sending field is a nondate.

Results of using date fields in addition -

Nondate second operandDate field second operand
Nondate first operand Nondate Date field
Date field first operand Date field Not allowed

Results of using date fields in subtraction -

Nondate second operandDate field second operand
Nondate first operand Nondate Not allowed
Date field first operand Date field Nondate