DIVISION of COMP-3 variable (intermediate datatype) -Query



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

DIVISION of COMP-3 variable (intermediate datatype) -Query

Postby hariharan_bk » Wed Apr 08, 2020 2:35 pm

Hi,
We have a situation where we divide the annual interest rate by 12, to calculate the monthly payment.


01  FIN-AMT       PIC  S9(15)V9(2)    COMP-3 VALUE 125000.00.          
01  NUM-MNTS   PIC  S9(04) COMP VALUE 24.        
01  FREQ1         PIC  S9(04) COMP VALUE 12.      
01  ANNL-RATE  PIC  S9(1)V9(6)  COMP-3 VALUE 0.0599.                
01  WS-TEMP-AMOUNT         PIC S9(08)V9(10)  COMP-3.      
 


I cannot provide the exact formulae, however I can mimic the same to explain the context.
We want to know what will be the intermediate value for this division - ANNL-RATE/12. We are suspecting some kind of truncation which is not providing us an expected result.

0.00499167 is the expectation, however we suspect we get some value around 0.00491....because of which we are losing some $10 amount in the WS-TEMP-AMOUNT

PIC clause for the intermediate value is unaware for us, to determine the issue reason. Please help us here.


COMPUTE WS-TEMP-AMOUNT = (FIN-AMT * NUM-NMTS * (ANNL-RATE/12) ) / FIN-AMT * (1+ANNL-RATE/12)
 
Many Thanks,
Harry
hariharan_bk
 
Posts: 73
Joined: Thu Mar 29, 2012 11:13 am
Has thanked: 5 times
Been thanked: 0 time

Re: DIVISION of COMP-3 variable (intermediate datatype) -Query

 

Re: DIVISION of COMP-3 variable (intermediate datatype) -Que

Postby sergeyken » Wed Apr 08, 2020 4:25 pm

For testing purposes: calculate each intermediate result separately, and print them.

It's normal practice for anyone doing the REAL software development, not only blah-blah-blah about it.

Why do you think that someone else will do YOUR job INSTEAD OF YOURSELF?
sergeyken
 
Posts: 100
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 2 times
Been thanked: 10 times

Re: DIVISION of COMP-3 variable (intermediate datatype) -Que

Postby enrico-sorichetti » Wed Apr 08, 2020 5:52 pm

because of which we are losing some $10


NOPE it depends on the point of view
until Your organisation demonstrates that the computations are carried according to the legal/law standards for financial computations
Your organisation is just stealing from the customer

in most countries the fiscal computations must be done with four decimal digits and the displayed with two
the financial computation IIRc have similar guidelines/rules

thats why the computations are carried on EXPLICITLY step by step to avoid un-auditable intermediate results
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2927
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 154 times

Re: DIVISION of COMP-3 variable (intermediate datatype) -Que

Postby Robert Sample » Wed Apr 08, 2020 6:56 pm

Appendix A of the Enterprise COBOL Programming Guide (for whichever version of COBOL your site uses) has explicit details on intermediate results and should have been your FIRST reference.

I also find it interesting that your post gives 8 digits after the decimal point for the result you're looking for, yet the variable you're dividing by 12 only has 6 digits after the decimal point. As long as you are using the calculation you presented, you won't get more than 6 digits after the decimal point in your intermediate results. And no, the intermediate results at the point of the division do NOT depend upon the 10 digits after the decimal point for WS-TEMP-AMOUNT.
Robert Sample
Global moderator
 
Posts: 3652
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 269 times

Re: DIVISION of COMP-3 variable (intermediate datatype) -Que

Postby hariharan_bk » Wed Apr 22, 2020 11:09 am

Thanks Robert and Enrico. I understand the reason for 6 digit decimal position for the rate division.
Most likely the focus part is on the rate division. I will alter the numerator variable definition and will understand the output decimal digits.

Thanks All.
Many Thanks,
Harry
hariharan_bk
 
Posts: 73
Joined: Thu Mar 29, 2012 11:13 am
Has thanked: 5 times
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post