Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
COBOL - ROUNDING OFF TO NEAREST 1 $

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
balaji81_k

Active User


Joined: 29 Jun 2005
Posts: 118

PostPosted: Wed Sep 26, 2012 12:18 pm    Post subject: COBOL - ROUNDING OFF TO NEAREST 1 $
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: 6968
Location: porcelain throne

PostPosted: Wed Sep 26, 2012 4:20 pm    Post subject:
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: 8165
Location: East Dubuque, Illinois, USA

PostPosted: Wed Sep 26, 2012 4:22 pm    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7315

PostPosted: Thu Sep 27, 2012 4:36 pm    Post subject: Reply to: COBOL - ROUNDING OFF TO NEAREST 1 $
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: 1243
Location: Israel

PostPosted: Thu Sep 27, 2012 9:40 pm    Post subject: Re: COBOL - ROUNDING OFF TO NEAREST 1 $
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts IEW2456E error when link-editing a C ... Senthilraj JCL & VSAM 0 Fri Oct 13, 2017 3:12 pm
No new posts Assembler Macro Copybook converted to... Ziquilix PL/I & Assembler 4 Tue Sep 26, 2017 3:07 am
This topic is locked: you cannot edit posts or make replies. Extract all "IF" Statements... Adarsh Damodaran CLIST & REXX 1 Wed Sep 06, 2017 9:28 am
No new posts ALPHABETIC check in COBOL vidyaa COBOL Programming 8 Thu Aug 17, 2017 7:13 pm
No new posts XML Parse for COBOL 5.2 Bhanu Praveen COBOL Programming 1 Sat Jul 08, 2017 8:58 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us