View previous topic :: View next topic
|
Author |
Message |
poongs Warnings : 1 New User
Joined: 24 Jan 2007 Posts: 28 Location: pune
|
|
|
|
Hi All,
My requirement is as follows.
i/p fileds are of S9(15)V9(02) COMP-3.
O/p field is 9(6).
o/p = (a+b)* 100
In this case , if the value of a and b are equal to 15225.10 and 30450.25 , then the o/p i'm getting is 49%.
The actual division result should be rounded i.e., the percentage i'm expecting is 50%.
My compute statement which i have used is as follows:
COMPUTE o/p ROUNDED =
((a / b) * 100
ON SIZE ERROR
MOVE ZEROES TO o/p |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Another case where intermediate results need to be understood to understand what happened to the fields. Sample code:
Code: |
05 VAR-1 PIC S9(15)V9(02) COMP-3.
05 VAR-2 PIC S9(15)V9(02) COMP-3.
05 VAR-3 PIC 9(06).
/
PROCEDURE DIVISION.
S1000-MAIN SECTION.
MOVE 15225.10 TO VAR-1.
MOVE 30450.25 TO VAR-2.
DISPLAY 'VAR-1 ' VAR-1.
DISPLAY 'VAR 2 ' VAR-2.
COMPUTE VAR-3 ROUNDED = (VAR-1 / VAR-2) * 100 .
DISPLAY 'VAR 3 ' VAR-3.
DISPLAY ' ' .
COMPUTE VAR-3 ROUNDED = (100 * VAR-1) / VAR-2.
DISPLAY 'VAR 3 ' VAR-3. |
produces output of
Code: |
VAR-1 00000000001522510
VAR 2 00000000003045025
VAR 3 000049
VAR 3 000050 |
|
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1248 Location: Richfield, MN, USA
|
|
|
|
See Appendix A in the Programming Guide for details about intermediate results. |
|
Back to top |
|
|
|