Purpose
Calculates the quotient of two values.
Syntax
►►─── DIVIDE divisor into dividend ───────────────────────────────────────────► ►──┬┬─────────────────────────────────┬──────────────────────────┬─ . ───────►◄ │├─ ROUNDED ───────────────────────┤ │ │├─ TRUNCATED ─────────────────────┤ │ │└─ ALLOWING assignment-condition ─┘ │ └── GIVING quotient ─┬─────────────┬─┬───────────────────────┬┘ ├─ ROUNDED ───┤ └─ REMAINDER remainder ─┘ └─ TRUNCATED ─┘
Parameters
Specifies the divisor in the divide operation. Divisor cannot be longer than eight bytes. Divisor can be an arithmetic expression, a numeric literal, or a user-defined variable.
Specifies the dividend in the divide operation. Dividend can be a user-defined variable.
(Coded immediately after dividend) Rounds the result of the division to the number of decimal positions found in dividend.
(Coded immediately after dividend) Truncates the result of the division to the number of decimal positions found in dividend.
The default specification is ROUNDED if COBOL moves are enabled is not selected and TRUNCATED if the option is selected.
Specifies which error conditions would normally abend and should cause control to be returned to the dialog for error handling. The list of allowable assignment-condition names can be found in the section entitled "Arithmetic and Assignment Command Status Condition."
Specifies the user-defined variable that receives the quotient of the DIVIDE operation.
(Coded after the GIVING parameter) Rounds the result of the division to the number of decimal positions found in quotient.
(Coded after the GIVING parameter) Truncates the result of the division to the number of decimal positions found in quotient.
The default specification is TRUNCATED if the REMAINDER parameter is specified.
If the REMAINDER parameter is not specified and if COBOL moves are enabled is not selected, the default specification is ROUNDED. If COBOL moves are enabled is selected, the default specification is TRUNCATED.
Specifies the field that receives the remainder of a DIVIDE operation. The remainder is calculated by subtracting the product of the truncated quotient and the divisor from the dividend.
If quotient and remainder refer to the same data field, the data field at the end of the DIVIDE command contains the quotient. The remainder is ignored.
Usage
Definition
The DIVIDE command is used to perform division. A variable data field value, a numeric literal, or the result of an arithmetic expression, which represents the divisor, is divided into a variable data field value, which represents the dividend.
The result of the division (the quotient) can be stored in the dividend data field or in a designated quotient data field. If the result is stored in a quotient data field, a data field to hold the remainder can also be specified.
Considerations
If dividend is to contain the result of the divide operation, ROUNDED or TRUNCATED can be specified immediately after dividend. The GIVING and REMAINDER parameters, however, cannot be specified.
If dividend is not to contain the result, ROUNDED or TRUNCATED cannot be specified immediately after dividend. The GIVING parameter must be specified. The GIVING parameter can be followed optionally by ROUNDED or TRUNCATED and the REMAINDER parameter.
Examples
The examples below illustrate the use of the DIVIDE command to divide the value in the TOT-SALES field by the value in the NUM-ORDERS field.
Example 1: Simple division
In this example, the quotient is placed in TOT-SALES:
DIVIDE NUM-ORDERS INTO TOT-SALES.
Example 2: Obtaining a truncated quotient with a remainder
In this example, the quotient is truncated and placed in TOT-SALES-Q. The remainder is placed in TOT-SALES-R:
DIVIDE NUM-ORDERS INTO TOT-SALES
GIVING TOT-SALES-Q TRUNCATED REMAINDER TOT-SALES-R.
|
Copyright © 2014 CA.
All rights reserved.
|
|