Divide

Syntax

DIVIDE expression variable [ GIVING variable ] [ ROUNDED ] [ REMAINDER variable ]
[ GS status ]

Parameters

Divide can be abbreviated as DV.

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