Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
neelesht

New User

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

 Posted: Wed Apr 18, 2007 9:33 pm    Post subject: What is the syntax for Round-Up in Cobol 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

dick scherrer

Site Director

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

Posted: Wed Apr 18, 2007 10:25 pm    Post subject:

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.
neelesht

New User

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

 Posted: Wed Apr 18, 2007 10:43 pm    Post subject: Re: What is the syntax for Round-Up in Cobol 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
dick scherrer

Site Director

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

 Posted: Wed Apr 18, 2007 11:22 pm    Post subject: You're welcome 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.
William Thompson

Global Moderator

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

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

 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....
dick scherrer

Site Director

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

 Posted: Thu Apr 19, 2007 3:41 am    Post subject: 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.
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics Linkage editor is part of COBOL, z/OS... ankit.jain COBOL Programming 4 Fri Apr 20, 2018 4:17 pm Difference between EQUAL and EQUAL TO... jithinraghavan COBOL Programming 3 Thu Apr 19, 2018 2:22 am Call COBOL or PLI with a click from w... vaibhav gs All Other Mainframe Topics 1 Mon Apr 16, 2018 7:29 pm COBOL MVS options BiswajitDG COBOL Programming 8 Fri Apr 06, 2018 12:35 am How syntax check at Bind time is diff... Poha Eater DB2 5 Wed Mar 21, 2018 9:16 pm

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us