View previous topic :: View next topic
|
Author |
Message |
jgantena
New User
Joined: 13 Aug 2008 Posts: 8 Location: Hyderabad
|
|
|
|
Hi Folks,
I am trying for division of two COMP-3 fields and store the resultant value into another COMP-3 field.
" COMPUTE WS-HRMFE-TOT-FEE-CRLIM-PERC =
((HRMFE-TOT-FEE-AMT
/ AMBS-CRLIM) * 100) "
WS-HRMFE-TOT-FEE-CRLIM-PERC , HRMFE-TOT-FEE-AMT , AMBS-CRLIM fields are "PIC S9(17) COMP-3."
But I am getting zeroes into the resultant field.
Can someone tell me how to do it.
Thanks,
Dev. |
|
Back to top |
|
|
guptae
Moderator
Joined: 14 Oct 2005 Posts: 1208 Location: Bangalore,India
|
|
|
|
Hello Dev,
Would you provid evalue of all the variables. |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
If I'm correct :
(HRMFE-TOT-FEE-AMT / AMBS-CRLIM) will be done first and the intermediate result will be stored based on the definition of both participating variables.
In this case probably s9(17) comp-3 thus 0
Multiplying 0 with 100 is still 0
try: COMPUTE WS-HRMFE-TOT-FEE-CRLIM-PERC =
(HRMFE-TOT-FEE-AMT * 100.00) / AMBS-CRLIM
or
COMPUTE WS-HRMFE-TOT-FEE-CRLIM-PERC =
((HRMFE-TOT-FEE-AMT * 1.00000) / AMBS-CRLIM) * 100
you could also not multiply by 100 and redefine your PERC |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
since you are only multiplying by 100 and have a pic s9(17) field, either- multilply by 10,000
- or
- use a PIC S9(15)V99 receiving field.
|
|
Back to top |
|
|
jgantena
New User
Joined: 13 Aug 2008 Posts: 8 Location: Hyderabad
|
|
|
|
Hi
I am having values in the fields HRMFE-TOT-FEE-AMT as 2444.00 , AMBS-CRLIM as 10000.00
I have tried changing the resultant field's " WS-HRMFE-TOT-FEE-CRLIM-PERC " pic clause to S9(14)v9(2) COMP-3
and the others retaining as "PIC S9(17) COMP-3." then i got the resultant value with round-off i.e.., instead of getting value 24.44 in " WS-HRMFE-TOT-FEE-CRLIM-PERC ", i got 24.00. |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
that makes sense :
2444.00 / 10000.00 = 0.24
0.24 * 100 = 24.00
better would be
2444.00 * 100 = 244400.00
244400.00 / 10000.00 = 24.44 |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
I have tried changing the resultant field's " WS-HRMFE-TOT-FEE-CRLIM-PERC " pic clause to S9(14)v9(2) COMP-3 |
Why an even number of digits? Suggest you use S9(15)v9(2) COMP-3.
The additional 1/2 byte will be there anyway and (IMHO) the S9(15)v9(2) is more clear. |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
Not understanding how COBOL handles intermediate results has bitten a lot of us. Please read how COBOL processes them in the Programming Guide, Appendix A. |
|
Back to top |
|
|
jgantena
New User
Joined: 13 Aug 2008 Posts: 8 Location: Hyderabad
|
|
|
|
hey folks,
I hav done what guyC has suggested and results were fine.
Thanks a lot to all of you.
Cheers,
Jai |
|
Back to top |
|
|
|