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

Author Message
sureshmanokar

New User

Joined: 21 Dec 2010
Posts: 11
Location: Bangalore

 Posted: Thu Feb 24, 2011 1:25 pm    Post subject: Comp-3 & Comp decimal data item validation for zero Hi, Can anyone please help me regarding the below scenario. Check whether a 3rd digit in COMP-3 decimal item is zero, if it is zero round it of to 2 decimal values else 3 decimal values. For example: 77 WS-NAV PIC S9(4)V9(5) COMP-3. 1) If the value is 1234.56089, then it should be rounded to 1234.56 2) If the value is 1234.56789, then it should be rounded to 1234.567

Kjeld

Active User

Joined: 15 Dec 2009
Posts: 365
Location: Denmark

 Posted: Thu Feb 24, 2011 1:48 pm    Post subject: If you make the truncation in another field, then subtract the truncated value from the original 5 decimal value. If the difference is less than .00100 then keep the truncated value else truncate to 3 decimal places.
enrico-sorichetti

Global Moderator

Joined: 14 Mar 2007
Posts: 10457
Location: italy

 Posted: Thu Feb 24, 2011 2:24 pm    Post subject: Reply to: Comp-3 & Comp decimal data item validation for learn the difference between truncate and round... since in Your example You truncate, the value of the third decimal digit is irrelevant and does not influence the process otherwise if You want to round, the approach is completely wrong! if the data refers to financial transaction rounding has also legal rules, ( improper rounding might be considered as a fraud attempt ) it might be wiser to review the process.
sureshmanokar

New User

Joined: 21 Dec 2010
Posts: 11
Location: Bangalore

 Posted: Thu Feb 24, 2011 2:56 pm    Post subject: Reply to: Comp-3 & Comp decimal data item validation for Enrico --> I apologize for my fault in the example. Kjeld --> No truncation should happen and below is my exact requirement. If third decimal place of WS-NAV = zero COMPUTE WS-POP ROUNDED to Two-decimal-places = WS-NAV / FN1-LOAD-PCT else COMPUTE WS-POP ROUNDED to Three-decimal-places = WS-NAV / FN1-LOAD-PCT. - Kindly advice.
enrico-sorichetti

Global Moderator

Joined: 14 Mar 2007
Posts: 10457
Location: italy

 Posted: Thu Feb 24, 2011 3:05 pm    Post subject: Reply to: Comp-3 & Comp decimal data item validation for at this point my other comment has the priority You are messing up the rounding rules! have the powers of Your organization and the people who set the requirements review their basic arithmetic skills for rounding! one reason to ask people to post the whole story and not just the silly technicalities is to provide better answers and not to waste time on senseless issues the way You have exposed the whole thing does not make sense the arithmetic approach is just plain wrong! there is difference between the computation process and the display process for example in italy all the IR computations must be carried on with 4 ( IIRC ) decimal digit precision and displayed with two digits
Robert Sample

Global Moderator

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

Posted: Thu Feb 24, 2011 4:14 pm    Post subject:

 Quote: 2) If the value is 1234.56789, then it should be rounded to 1234.567
sureshmanokar, either you are using a mathematical system unlike the one I learned in my younger days, or you are flat out WRONG. 1234.56789 rounded to the third decimal place would be 1234.568, not 1234.567 -- PERIOD. The rule was, and is, that the next digit being 5 or more causes the value to go up by one. Since 8 is more than 5, the 7 becomes an 8.

You should move the COMP-3 data to a DISPLAY variable which has a PIC X redefined on it. You can then use reference modification to theck the digit you want to be zero and do your rounding (assuming that really is what you want) appropriately.
Kjeld

Active User

Joined: 15 Dec 2009
Posts: 365
Location: Denmark

Posted: Thu Feb 24, 2011 8:22 pm    Post subject: Re: Reply to: Comp-3 & Comp decimal data item validation

 sureshmanokar wrote: Enrico --> I apologize for my fault in the example. Kjeld --> No truncation should happen and below is my exact requirement.

Unfortunately this is not Psychic Day, and your example suggested truncation so that is what I suggested. But the proceedings in this thread indicates that you have to get truncation and rounding terms clearly defined, both what they mean technically, and what they mean in your organisation and to the requirement originators.

Nevertheless, my example of testing the 3rd decimal digit uses truncation on purpose to isolate the 3 low order decimals. You can use that, or possibly some bit masking to obtain a value without the 3 low order decimal digits.

Alternatively, you can use the method Robert suggested picking out the 3. decimal digit from a display representation of the value.

A real nerd would redefine the packed field to extract the 2. lowest byte, which would have a value of x'00' to x'09' if your requirement condition is true.
sureshmanokar

New User

Joined: 21 Dec 2010
Posts: 11
Location: Bangalore

 Posted: Fri Feb 25, 2011 12:17 pm    Post subject: Reply to: Comp-3 & Comp decimal data item validation for Robert sample: Hi Robert, the value 1234.56789 rounded to the third decimal place would be 1234.568 as per our common mathematical system. I made a TYPO error in my example, my sincere apologize for that. And thanks for your valuable suggestion...! I tried it before & got the perfect output what i need . Below is the program. Program:- WORKING-STORAGE SECTION. 01 WS-POP-NAV-GROUP. 05 WS-POP PIC S9(4)V9(5) COMP. 05 WS-NAV PIC S9(4)V9(5) COMP. 05 WS-NAV-NUMERIC PIC S9(4)V9(5). 05 WS-BRK-PT-POP-THREE PIC S9(4)V9(3). 05 WS-BRK-PT-POP-TWO PIC S9(4)V9(2). 77 I PIC 9(2) VALUE 0. PROCEDURE DIVISION. MAIN-PARA. MOVE 1234.56789 TO WS-NAV. DISPLAY 'WS-NAV :' WS-NAV. MOVE WS-NAV TO WS-NAV-NUMERIC. DISPLAY 'WS-NAV-NUM :' WS-NAV-NUMERIC. IF WS-NAV-NUMERIC(7:1) = 0 COMPUTE WS-BRK-PT-POP-TWO ROUNDED= WS-NAV MOVE WS-BRK-PT-POP-TWO TO WS-POP DISPLAY 'WS-POP :' WS-POP ELSE COMPUTE WS-BRK-PT-POP-THREE ROUNDED= WS-NAV MOVE WS-BRK-PT-POP-THREE TO WS-POP DISPLAY 'WS-POP :' WS-POP END-IF. STOP RUN. My sincere thanks to Robert & Kjeld for their patience
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics 3270 Data stream error Benchwarmer CICS 6 Tue Apr 17, 2018 12:06 am How to list data set names with diffe... murali.andaluri CLIST & REXX 8 Thu Apr 12, 2018 11:33 pm Invalid XML character while producing... nikhil.bhole IBM Tools 4 Tue Mar 20, 2018 1:24 am Get the list of data sets on DASD and... rakaitn JCL & VSAM 3 Thu Mar 08, 2018 12:38 pm How to group and sum the decimal value sakrat DFSORT/ICETOOL 2 Tue Mar 06, 2018 9:13 pm

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