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
 

 

Comp-3 & Comp decimal data item validation for zero

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

New User


Joined: 21 Dec 2010
Posts: 11
Location: Bangalore

PostPosted: Thu Feb 24, 2011 1:25 pm    Post subject: Comp-3 & Comp decimal data item validation for zero
Reply with quote

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

Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Thu Feb 24, 2011 1:48 pm    Post subject:
Reply with quote

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.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10274
Location: italy

PostPosted: Thu Feb 24, 2011 2:24 pm    Post subject: Reply to: Comp-3 & Comp decimal data item validation for
Reply with quote

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.
Back to top
View user's profile Send private message
sureshmanokar

New User


Joined: 21 Dec 2010
Posts: 11
Location: Bangalore

PostPosted: Thu Feb 24, 2011 2:56 pm    Post subject: Reply to: Comp-3 & Comp decimal data item validation for
Reply with quote

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.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10274
Location: italy

PostPosted: Thu Feb 24, 2011 3:05 pm    Post subject: Reply to: Comp-3 & Comp decimal data item validation for
Reply with quote

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
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8117
Location: East Dubuque, Illinois, USA

PostPosted: Thu Feb 24, 2011 4:14 pm    Post subject:
Reply with quote

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.
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

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

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.
Back to top
View user's profile Send private message
sureshmanokar

New User


Joined: 21 Dec 2010
Posts: 11
Location: Bangalore

PostPosted: Fri Feb 25, 2011 12:17 pm    Post subject: Reply to: Comp-3 & Comp decimal data item validation for
Reply with quote

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 icon_smile.gif . 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 icon_smile.gif
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 copying data without knowing location arunsoods DFSORT/ICETOOL 6 Thu Jul 20, 2017 1:03 pm
This topic is locked: you cannot edit posts or make replies. Fetching data from BAI File arunsoods JCL & VSAM 1 Wed Jul 19, 2017 4:28 pm
No new posts Loading data to table gives wrong for... Raghu navaikulam DB2 18 Thu Jul 13, 2017 2:11 pm
No new posts SQL - select data available in index Nileshkul DB2 3 Mon Jun 26, 2017 1:30 am
No new posts NDM syntax checking without actually ... GAPX1 All Other Mainframe Topics 0 Wed Jun 07, 2017 2:36 am


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