Thursday, 14 August 2014

COBOL Rounded Clause | ROUNDED in COBOL Example.

COBOL
COBOL ROUNDED CLAUSE
After decimal point alignment, the number of places in the fraction of the result of an arithmetic operation is compared with the number of places provided for the fraction of the resultant identifier. 
When the size of the fractional result exceeds the number of places provided for its storage, truncation occurs unless the ROUNDED phrase is specified. When ROUNDED phrase is specified, the least significant digit of the resultant identifier is increased by 1 whenever the most significant digit of the excess is greater than or equal to 5. 
When the resultant identifier is described by a PICTURE clause containing rightmost Ps and when the number of places in the calculated result exceeds the number of integer positions specified, rounding or truncation occurs, relative to the rightmost integer position for which storage is allocated.
Syntax : 
COBOL ROUNDED
ROUNDED  in COBOL Example.

Example: 
COMPUTE SALES-TAX ROUNDED = SALES-AMOUNT * .0785

Rules:
  1. The ROUNDED option may be specified with any arithmetic operation.  If used, it directly follows the data-name specified as the receiving field.
  2. When the resultant field cannot accommodate all the decimal positions in the answer and the ROUNDED option is not specified, truncation of decimal positions will occur.
  3. When the ROUNDED option is used, the result will be rounded to the PICTURE specification of the receiving field.
  4. If ROUNDED and REMAINDER are used in the same DIVIDE, ROUNDED must appear first.
You can code the Rounded clause whenever the result of a calculation can have more decimal places than is specified in the picture of the result field. If you don’t use the Rounded clause, the extra decimal places are truncated


COBOL Tutorial

Have a look of  CICS Top 100 Interview Questions Part II.

No comments:

Post a Comment