DIVIDE Statement COBOL

The DIVIDE statement divides one numeric data item into another and stores the quotient and remainder.

Format 1:Divide…Into

Divide…Into

Format 2:Divide…Into…Giving

Divide…Into…Giving

Format 3:Divide…By…Giving

Divide…By…Giving

Format 4:Divide…Into…Giving…Remainder

Divide…Into…Giving…Remainder

Format 5:Divide…By…Giving…Remainder

Divide…By…Giving…Remainder

In Format 1, the value of identifier-1 or literal-1 is divided into the value of each identifier-2. The value of each dividend (identifier-2) is replaced by this quotient.

In Format 2, the value of identifier-1 or literal-1 is divided into the value of identifier-2 or literal-2 and the result is stored in each identifier-3.

In Format 3, the value of identifier-2 or literal-2 is divided by the value of identifier-1 or literal-1 and the result is stored in each identifier-3.

In Format 4, the value of identifier-1 or literal-1 is divided into the value of identifier-2 or literal-2; the result is stored in identifier-3, and the remainder is stored in identifier-4.

In Format 5, the value of identifier-2 or literal-2 is divided by the value of identifier-1 or literal-1; the result is stored in identifier-3, and the remainder is stored in identifier-4.

Each identifier must refer to an elementary numeric item, except that any identifier associated with the GIVING phrase may refer to either an elementary numeric item or an elementary numeric edited item.

Each literal must be a numeric literal.

Additional rules and explanations regarding features of the DIVIDE statement that are common to other arithmetic statements can be found in the discussion of common rules.See in particular the discussions of the ROUNDED phrase, the size error condition, overlapping operands, modes of operation, composite size, and incompatible data.

REMAINDER Phrase

GIVING identifier-3 [ROUNDED ] REMAINDER identifier-4

Formats 4 and 5 are used when a remainder from the division operation is desired, namely identifier-4 .The remainder is defined as the result of subtracting the product of the quotient (identifier-3 ) and the divisor from the dividend. If identifier-3 is defined as a numeric edited item, the quotient used to calculate the remainder is an intermediate field that contains the unedited quotient.If ROUNDED is used, the quotient used to calculate the remainder is an intermediate field which contains the quotient of the DIVIDE statement, truncated rather than rounded.The intermediate field used in these calculations has the same number of digit positions and the same scale as identifier-3.

In Formats 4 and 5, the accuracy of the REMAINDER data item (identifier-4) is defined by the calculation described above.

Appropriate decimal alignment and truncation (not rounding) is performed for the content of the data item referenced by identifier-4, as needed.When the composite of the quotient and dividend operands contains more than 19 digits, the accuracy of the REMAINDER data item may be greater than that obtainable by the use of a COMPUTE statement which duplicates the calculation described above.

When the ON SIZE ERROR phrase is used in Formats 4 and 5, the following rules pertain:

  1. If the size error condition occurs on the quotient, no remainder calculation is meaningful.Thus, the contents of the data items referenced by both identifier-3 and identifier-4 remain unchanged.
  2. If the size error condition occurs on the remainder, the contents of the data item referenced by identifier-4 remain unchanged. It is the user’s responsibility to determine which situation has actually occurred.

DIVIDE Statement Examples



Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

COBOL Topics