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

Author Message
jgantena

New User

Joined: 13 Aug 2008
Posts: 8

 Posted: Thu Jan 07, 2010 2:50 pm    Post subject: How to do Divide Arithmetic operation for COMP-3 fields 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.

guptae

Moderator

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

 Posted: Thu Jan 07, 2010 2:57 pm    Post subject: Hello Dev, Would you provid evalue of all the variables.
GuyC

Senior Member

Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

 Posted: Thu Jan 07, 2010 3:12 pm    Post subject: 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
dbzTHEdinosauer

Global Moderator

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

 Posted: Thu Jan 07, 2010 3:16 pm    Post subject: since you are only multiplying by 100 and have a pic s9(17) field, eithermultilply by 10,000oruse a PIC S9(15)V99 receiving field.
jgantena

New User

Joined: 13 Aug 2008
Posts: 8

 Posted: Thu Jan 07, 2010 3:38 pm    Post subject: 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.
GuyC

Senior Member

Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

 Posted: Thu Jan 07, 2010 4:01 pm    Post subject: 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
dick scherrer

Site Director

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

Posted: Thu Jan 07, 2010 10:08 pm    Post subject:

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.
Terry Heinze

JCL Moderator

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

 Posted: Fri Jan 08, 2010 6:36 am    Post subject: 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.
jgantena

New User

Joined: 13 Aug 2008
Posts: 8