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

Questions on compute verb


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

New User


Joined: 12 Oct 2007
Posts: 8
Location: Trivandrum

PostPosted: Sat Dec 15, 2007 3:27 pm
Reply with quote


Hi all,

Please help me to clarify the doubts on Compute usages in Arithmetic Operations.

What all are the demerits of Compute verb?
Will it make any lagging to memory storage while operation?
Which one is fastest Compute or Add?
Any difference in precision / accuracy between Compute and ADD operations?

Thanks and Regards,

Arun
Back to top
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Sat Dec 15, 2007 4:35 pm
Reply with quote

Arun,
Quote:
Which one is fastest Compute or Add?

Why dont 'you' some test and let us know?

Quote:
Any difference in precision / accuracy between Compute and ADD operations?

Precision and accuracy depends on how you 'declare' the data.
Back to top
View user's profile Send private message
raak

Active User


Joined: 23 May 2006
Posts: 166
Location: chennai

PostPosted: Sat Dec 15, 2007 5:16 pm
Reply with quote

One of the differences is in the usage of ON SIZE ERROR command..U can use it with COMPUTE, but not with ADD...
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: Sat Dec 15, 2007 11:28 pm
Reply with quote

Hello,

The performance will be similar. If the calculation is complex, i'd suggest using code that will be easiest to read/maintain later.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sat Dec 15, 2007 11:42 pm
Reply with quote

Hi Arun,

One of the most serious drawbacks when using COMPUTE (it's a DIVIDE problem, not an ADD problem) is its malfunctioning when using a quotient with an insufficent number of decimal places.

Here's an example of the problem:

* THE ANSWER SHOULD BE 24.8
Code:
COMPUTE WS-PERCENT-999.9    = (248 / 1000) * 100.
COMPUTE WS-PERCENT-999.99   = (248 / 1000) * 100.
COMPUTE WS-PERCENT-999.999  = (248 / 1000) * 100.
COMPUTE WS-PERCENT-999.9999 = (248 / 1000) * 100.

What each of the above produces:

PIC 999.9: 020.0
PIC 999.99: 024.00
PIC 999.999: 024.800
PIC 999.9999: 024.8000
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
This topic is locked: you cannot edit posts or make replies. regarding COBOL WRITE verb (VB File H... COBOL Programming 9
No new posts Comp interview questions Mainframe Interview Questions 5
No new posts Compute statement with Cobol Z/os 5.2 COBOL Programming 2
No new posts Interview Questions on Cobol DB2 program Mainframe Interview Questions 5
No new posts ROUNDED Problem with COMPUTE statement COBOL Programming 11
Search our Forums:

Back to Top