View previous topic :: View next topic
|
Author |
Message |
balaji81_k
Active User
Joined: 29 Jun 2005 Posts: 155
|
|
|
|
Hi ,
Iam facing issue while iam getting rounding off the input amount value to the output file. I need to populate the actual amount value as wellas it rounding of to nearest 1 $ values .
for ex : if my input is -339.08 my output amount is -339.08 and
round of will be -339 and if -339.5 then i need to get -340
in round off variable . Here is my code .
ID DIVISION.
PROGRAM-ID. PGM2.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-INPUT-AMOUNT PIC S9(09)V99 COMP-3.
01 WS-OUTPUT-AMOUNT PIC S9(06)V99.
01 WS-OUT-AMOUNT-RUND REDEFINES
WS-OUTPUT-AMOUNT PIC S9(08).
PROCEDURE DIVISION.
MAIN.
MOVE -339.08 TO WS-INPUT-AMOUNT.
MOVE WS-INPUT-AMOUNT TO WS-OUTPUT-AMOUNT.
COMPUTE WS-OUT-AMOUNT-RUND ROUNDED
= WS-INPUT-AMOUNT .
STOP RUN.
meanwhile iam also trying to get this by having divide by 10 logic . I need to achive this with redefines clause as mentioned for round of f variable .
Can any help me out on this ?Please. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
what is your issue?
what are the actual values that you are generating??? |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Rounding requires you to do something in the PROCEDURE DIVISION. You cannot achieve rounded results merely by using REDEFINES -- ever. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Another disappearee, perhaps.
This might help. |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
balaji81_k wrote: |
Code: |
01 WS-OUTPUT-AMOUNT PIC S9(06)V99.
01 WS-OUT-AMOUNT-RUND REDEFINES WS-OUTPUT-AMOUNT PIC S9(08).
|
Code: |
MOVE -339.08 TO WS-INPUT-AMOUNT.
MOVE WS-INPUT-AMOUNT TO WS-OUTPUT-AMOUNT.
COMPUTE WS-OUT-AMOUNT-RUND ROUNDED = WS-INPUT-AMOUNT . |
|
Unfortunately, the way you're doing this is quite wrong.
Both fields WS-OUTPUT-AMOUNT and WS-OUT-AMOUNT-RUND occupy the same 8 bytes of memory.
After the 1st MOVE, you have '0003390Q' in this area. If you look at it through the WS-OUTPUT-AMOUNT field, you will see -339.08.
If you look at it through the WS-OUT-AMOUNT-RUND field you will see -33908.
After the COMPUTE, you will have '0000033R' in memory. field WS-OUT-AMOUNT-RUND will have a value of -339 (as requested)
but looking at field WS-OUTPUT-AMOUNT will show you -3.39.
This requirement look strange to me:
balaji81_k wrote: |
I need to achive this with redefines clause as mentioned for round of variable. |
|
|
Back to top |
|
|
|