IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

COBOL - ROUNDING OFF TO NEAREST 1 $


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
balaji81_k

Active User


Joined: 29 Jun 2005
Posts: 155

PostPosted: Wed Sep 26, 2012 12:18 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Sep 26, 2012 4:20 pm
Reply with quote

Quote:
Iam facing issue


what is your issue?

what are the actual values that you are generating???
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Sep 26, 2012 4:22 pm
Reply with quote

Rounding requires you to do something in the PROCEDURE DIVISION. You cannot achieve rounded results merely by using REDEFINES -- ever.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Sep 27, 2012 4:36 pm
Reply with quote

Another disappearee, perhaps.

This might help.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Thu Sep 27, 2012 9:40 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top