IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to do Divide Arithmetic operation for COMP-3 fields


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
jgantena

New User


Joined: 13 Aug 2008
Posts: 8
Location: Hyderabad

PostPosted: Thu Jan 07, 2010 2:50 pm
Reply with quote

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

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Thu Jan 07, 2010 2:57 pm
Reply with quote

Hello Dev,

Would you provid evalue of all the variables.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Thu Jan 07, 2010 3:12 pm
Reply with quote

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

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Jan 07, 2010 3:16 pm
Reply with quote

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

New User


Joined: 13 Aug 2008
Posts: 8
Location: Hyderabad

PostPosted: Thu Jan 07, 2010 3:38 pm
Reply with quote

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

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Thu Jan 07, 2010 4:01 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Thu Jan 07, 2010 10:08 pm
Reply with quote

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
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Fri Jan 08, 2010 6:36 am
Reply with quote

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

New User


Joined: 13 Aug 2008
Posts: 8
Location: Hyderabad

PostPosted: Fri Jan 08, 2010 2:39 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Converting ASCII values to COMP-3 (ZD... JCL & VSAM 2
No new posts Interviewers are surprised with my an... Mainframe Interview Questions 6
No new posts Concatenate 2 fields (usage national)... COBOL Programming 2
No new posts Cobol COMP-2 fields getting scrambled... Java & MQSeries 6
Search our Forums:

Back to Top