Syntax
DIVIDE expression variable [ GIVING variable ] [ ROUNDED ] [ REMAINDER variable ] [ GS status ]
Parameters
Divide can be abbreviated as DV.
expression variable
The number expression to divide the qualifier by. The qualifier also receives the result if the Giving command option is not specified.
GIVING variable
GIVING can be abbreviated as GIV. Directs the result to the specified qualifier.
ROUNDED
ROUNDED can be abbreviated as ROU. Rounds the result when truncation occurs.
REMAINDER variable
REMAINDER can be abbreviated as REM. Directs the true remainder of the division to the specified remainder number-primitive variable.
GS status
Indicates division by zero or arithmetic overflow using the specified variable. On MCP-based systems, if GS isn’t used and an overflow occurs, the system or report could abnormally terminate.
Description
The Divide logic command divides the value of a numeric expression by the value of a number-primitive variable, and stores the result in that variable, or optionally divides the result of the second expression by the result of the first expression and stores the result in a specified result variable.
If the Rounded command option is specified in conjunction with the Remainder and Giving command options, the result is rounded, but the value of the remainder is still valid.
If the divisor is zero or an arithmetic overflow occurs, the result is zero.
The behavior of the Divide logic command can be replicated using the '/' arithmetic operator. Use of arithmetic operators, where possible, rather than arithmetic logic commands, is the LDL+ preferred format.
Failure behavior
The Glb.Status built-in segment attribute is not set. Use the GS command option to test for division by zero or arithmetic overflow.
Example
This example uses three signed number-primitive variables, Amount1, Amount2, and Amount3, all or which are of length 5.
Amount1 := 14 Divide 3 Amount1 Rounded : Amount1 = 5 Amount1 := 14 Divide 3 Amount1 Giving Amount2 Remainder Amount3 : Amount1 = 14, Amount2 = 4, Amount3 = 2