This document covers the following topics:
Related Statements: ADD
| COMPRESS
|
COMPUTE
|
EXAMINE
|
MOVE
|
MOVE ALL
|
MULTIPLY
|
RESET
|
SEPARATE
|
SUBTRACT
Belongs to Function Group: Arithmetic and Data Movement Operations
The DIVIDE
statement is used to divide an arithmetic
expression or operand into two operands.
Note:
Concerning Division by Zero: If an attempt is made to use a divisor
(operand1
) which is zero, either an
error message or a result equal to zero will be returned; this depends on the
setting of the session parameter ZD
(described in the
Parameter Reference documentation).
DIVIDE
[ROUNDED ]
|
INTO
operand2 |
For explanations of the symbols used in the syntax diagrams, see Syntax Symbols.
Operand Definition Table:
Operand | Possible Structure | Possible Formats | Referencing Permitted | Dynamic Definition | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
operand1
|
C | S | A | N | N | P | I | F | yes | no | |||||||||
operand2
|
S | A | M | N | P | I | F | yes | no |
Syntax Element Description:
Syntax Element | Description |
---|---|
arithmetic-expression |
See Arithmetic
Expression in the COMPUTE statement.
|
operand1 INTO
operand2
|
Operands:
operand2 := operand2 / operand1 If an The number of decimal positions for the result of the division is
evaluated from the result field (that is,
For the precision of the result, see Rules for Arithmetic Assignments, Precision of Results of Arithmetic Operations in the Programming Guide. |
ROUNDED
|
ROUNDED Option:
If you specify the keyword For information on rounding, see Rules for Arithmetic Assignment, Field Truncation and Field Rounding in the Programming Guide. |
DIVIDE
[ROUNDED ]
|
INTO
|
GIVING
operand3 |
For explanations of the symbols used in the syntax diagram, see Syntax Symbols.
Operand Definition Table:
Operand | Possible Structure | Possible Formats | Referencing Permitted | Dynamic Definition | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
operand1
|
C | S | A | N | N | P | I | F | yes | no | ||||||||||
operand2
|
C | S | A | N | N | P | I | F | yes | no | ||||||||||
operand3
|
S | A | A | U | N | P | I | F | B* | yes | yes |
* Format B of operand3
may be
used only with a length of less than or equal to 4.
Syntax Element Description:
Syntax Element | Description |
---|---|
arithmetic-expression |
See Arithmetic
Expression in the COMPUTE statement.
|
operand1 INTO
operand2
GIVING
operand3
|
Operands:
The result of the division is stored in
operand3 := operand2 / operand1 The number of decimal positions for the result of the division is
evaluated from the result field (that is,
For the precision of the result, see Rules for Arithmetic Assignments, Precision of Results of Arithmetic Operations in the Programming Guide. |
ROUNDED
|
ROUNDED Option:
If you specify the keyword For information on rounding, see Rules for Arithmetic Assignment, Field Truncation and Field Rounding in the Programming Guide. |
DIVIDE
|
INTO |
[GIVING
operand3]
REMAINDER
operand4 |
For explanations of the symbols used in the syntax diagrams, see Syntax Symbols.
Operand Definition Table:
Operand | Possible Structure | Possible Formats | Referencing Permitted | Dynamic Definition | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
operand1
|
C | S | A | N | N | P | I | yes | no | |||||||||||
operand2
|
C | S | A | N | N | P | I | yes | no | |||||||||||
operand3
|
S | A | A | U | N | P | I | F | B* | T | yes | yes | ||||||||
operand4
|
S | A | A | U | N | P | I | F | B* | T | yes | yes |
* Format B of operand3
and
operand4
may be used only with a length
of less than or equal to 4.
Syntax Element Description:
Syntax Element | Description |
---|---|
arithmetic-expression |
See Arithmetic
Expression in the COMPUTE statement.
|
Operands:
If the If |
|
GIVING
operand3
|
GIVING Clause:
If this clause is used,
The number of decimal positions for the result of the division is
evaluated from the result field (that is,
For the precision of the result, see Rules for Arithmetic Assignments, Precision of Results of Arithmetic Operations (in the Programming Guide). |
REMAINDER
operand4
|
REMAINDER Clause:
The remainder of the division is placed into the field specified in
For each of these steps, the rules described in Precision of Results of Arithmetic Operations in the Programming Guide apply. |
** Example 'DIVEX1': DIVIDE ************************************************************************ DEFINE DATA LOCAL 1 #A (N7) INIT <20> 1 #B (N7) 1 #C (N3.2) 1 #D (N1) 1 #E (N1) INIT <3> 1 #F (N1) END-DEFINE * DIVIDE 5 INTO #A WRITE NOTITLE 'DIVIDE 5 INTO #A' 20X '=' #A * RESET INITIAL #A DIVIDE 5 INTO #A GIVING #B WRITE 'DIVIDE 5 INTO #A GIVING #B' 10X '=' #B * DIVIDE 3 INTO 3.10 GIVING #C WRITE 'DIVIDE 3 INTO 3.10 GIVING #C' 8X '=' #C * DIVIDE 3 INTO 3.1 GIVING #D WRITE 'DIVIDE 3 INTO 3.1 GIVING #D' 9X '=' #D * DIVIDE 2 INTO #E REMAINDER #F WRITE 'DIVIDE 2 INTO #E REMAINDER #F' 7X '=' #E '=' #F * END
DIVIDE 5 INTO #A #A: 4 DIVIDE 5 INTO #A GIVING #B #B: 4 DIVIDE 3 INTO 3.10 GIVING #C #C: 1.03 DIVIDE 3 INTO 3.1 GIVING #D #D: 1 DIVIDE 2 INTO #E REMAINDER #F #E: 1 #F: 1