Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

What is the syntax for Round-Up in Cobol

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

New User


Joined: 24 Jul 2006
Posts: 99
Location: Los Angeles

PostPosted: Wed Apr 18, 2007 9:33 pm    Post subject: What is the syntax for Round-Up in Cobol
Reply with quote

Hi All,

I want to round-up one of the variable.
How do I do this ?

Example
Var(A) signed.

if its value is 0.22 I want to round it to 1 and also if its 0.99 then also round it to 1.
if its 1.01 then it should be rounded to 2.
Please give me the exact syntax.

Thanks
-Neelesh
Back to top
View user's profile Send private message

dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Wed Apr 18, 2007 10:25 pm    Post subject:
Reply with quote

Hello,

One way might be to do your calculation resulting in a field with 2 implied decimals (05 MY-AMT PIC S9(7)V99 COMP-3). After your calculation, compute a new field (05 NEW-AMT PIC S9(7) COMP-3) with
Code:
COMPUTE NEW-AMT = MY-AMT + .99


This should generate the answer you want.
Back to top
View user's profile Send private message
neelesht

New User


Joined: 24 Jul 2006
Posts: 99
Location: Los Angeles

PostPosted: Wed Apr 18, 2007 10:43 pm    Post subject: Re: What is the syntax for Round-Up in Cobol
Reply with quote

Hi Dick,

thanks alot.

Is there any thing called ROUND-UP in Cobol, since I dont want to define any working storage variable.

Thanks
-Neelesh
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Wed Apr 18, 2007 11:22 pm    Post subject:
Reply with quote

You're welcome icon_smile.gif

COBOL has a ROUNDED option, but it 1/2 adjusts by .5.

If you do a computation with fields that have decimal places, you will have decimal places in the result. If you want to round up to the next full digit and have the answer be 2, i believe you will need to create a result with no decimal places - otherwise you would at best get 2.00 for a result.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Thu Apr 19, 2007 1:39 am    Post subject: Re: What is the syntax for Round-Up in Cobol
Reply with quote

neelesht wrote:
if its value is 0.22 I want to round it to 1 and also if its 0.99 then also round it to 1.
if its 1.01 then it should be rounded to 2.
In very few words, "that ain't rounding"!
The three ways to "round" are:
Truncate - round down
Round - known as half round
And round up - ok, the word "round" is in there....

Code:
01 filler.
  05 NumberToRoundUp pic s9(5)v99.
  05 NumberRoundedUp pic s9(5)v99.
  05 VAR pic s9(5)v99.
  05 filler redefines VAR.
    10 filler pic x(5).
    10 CNT pic x(2).

move NumberToRoundUp to VAR
if cnt = '00'
   continue
else
   add 1 to VAR
   move zero to CNT
end-if
move VAR to NumberRoundedUp

Or
Code:
01 filler.
  05 NumberToRoundUp pic s9(5)v99.
  05 NumberRoundedUp pic s9(5)v99.
  05 VAR pic s9(5).

move NumberToRoundUp to VAR
if VAR = NumberToRoundUp
   continue
else
   add 1 to VAR
   move VAR to NumberRoundedUp
end-if

Or you might play with integer functions.... icon_lol.gif
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu Apr 19, 2007 3:41 am    Post subject:
Reply with quote

Hello,

The required result is quite common at places i've supported.

Let's say that there is a container system that is of fixed size for loading on trucks and trains. They have been designed to maximize the product load for the transport type. These containers may be loaded with lots of different product. When an order is received that takes 5.02 containers, 6 must be allocated to handle that order.

In those cases the "result" was "rounded" by .99 to ensure everything was accounted for. Don't know if this is what Neelesh is doing, but we used this at several places.

Neelesh - can you live with 2.00 for an answer?

Unless there is some "real" problem with creating a new field with no decimal places, i'd recommend definng a new result field with no decimals.
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 FINDREP Syntax Error seahawk789 DFSORT/ICETOOL 4 Thu Mar 09, 2017 10:11 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Execute TSO ACF commands from COBOL-I... supreethi.srid TSO/ISPF 0 Tue Feb 21, 2017 5:19 pm
No new posts Mainframe Interview Questions CICS,CO... akshathan Mainframe Interview Questions 6 Thu Feb 09, 2017 6:38 pm
No new posts Submit job from Cobol with input data abdulrafi COBOL Programming 4 Wed Feb 01, 2017 12:41 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us