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
 

 

How to do Divide Arithmetic operation for COMP-3 fields

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: How to do Divide Arithmetic operation for COMP-3 fields
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: 1187
Location: Bangalore,India

PostPosted: Thu Jan 07, 2010 2:57 pm    Post subject:
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    Post subject:
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: 6968
Location: porcelain throne

PostPosted: Thu Jan 07, 2010 3:16 pm    Post subject:
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    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Thu Jan 07, 2010 10:08 pm    Post subject:
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    Post subject:
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    Post subject:
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    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 How to write Specific Fields from Mul... Padhu SYNCSORT 6 Thu Jul 06, 2017 10:26 am
No new posts Validate date and numeric fields and ... Rick Silvers DFSORT/ICETOOL 6 Thu May 11, 2017 6:51 pm
No new posts Sum Fields ballaswaroop DFSORT/ICETOOL 4 Tue May 02, 2017 11:07 am
No new posts DFSORT MUL FIELDS tspr52 DFSORT/ICETOOL 16 Fri Mar 03, 2017 11:53 pm
No new posts Sort two file having same field, one ... himanshu malik DFSORT/ICETOOL 7 Thu Feb 02, 2017 10:09 am


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