Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 6: Procedure Division


ROUNDED option

  • ROUNDED option can be used with ADD, SUBTRACT, DIVIDE and MULTIPLY verbs
  • ROUNDED option is used to round off the value as per PICTURE clause specification of the receiving field
  • It generally takes effect when after decimal point alignment, the result calculated must be truncated on the right hand side
  • ROUNDED option is usually coded following the field to be rounded. However, when coded with REMAINDER option of DIVIDE verb, it is prefixed
  • Below example will help you understand use of ROUNDED
    In data declaration,

    05 DATA-A PIC 99V999 VALUE 11.432. 05 DATA-B PIC 99V999 VALUE 21.863. 05 DATA-C PIC 99V9.

    In PROCEDURE DIVISION,

    ADD DATA-A DATA-B GIVING DATA-C ROUNDED

    After execution of above ADD statement,
           DATA-A will have 11.432
           DATA-B will have 21.863
           DATA-C will have 33.3
    In above case, the actual sum of DATA-A and DATA-B is 33.295 but since ROUNDED option is used, the result is rounded off and hence DATA-C contains final value as 33.3. If suppose, ROUNDED option was not coded, then DATA-C would have final value as 33.2.
  • Using ROUNDED option for REMAINDER option of DIVIDE statement:-

    DIVIDE DATA-A INTO DATA-B GIVING DATA-C ROUNDED REMAINDER DATA-D

    * Note, in above DIVIDE statement, since ROUNDED is used for REMAINDER, it is prefixed.



Advertisements






© copyright mainframebug.com
Privacy Policy