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
 

 

Help needed on divide statement

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
nithinlenin

New User


Joined: 06 Feb 2007
Posts: 19
Location: Hyderabad

PostPosted: Sun Jun 17, 2007 12:33 pm    Post subject: Represnt the statement using COMPUTE instead of DIVIDE
Reply with quote

hi

DIVIDE ((WS-REG-DOL1 * (10 ** 14)) + (WS-REG-DOL2)) * 10000
BY (10 ** 14)
GIVING WS-R-DOL1
REMAINDER WS-R-DOL2


can i represnt the given statement using COMPUTE as this is giving an error ..
i need both the quotient and the ramainder
Back to top
View user's profile Send private message

William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Sun Jun 17, 2007 4:52 pm    Post subject:
Reply with quote

Strange question....
Assuming WS-REG-DOL2 is smaller than 10 to the 14th,
WS-R-DOL1 = WS-REG-DOL1 and WS-R-DOL2 = WS-REG-DOL2.
If WS-REG-DOL2 might be greater than 10 to the 14th, you could do a simple divide with remainder and add the giving to the above WS-R-DOL1.
Back to top
View user's profile Send private message
nithinlenin

New User


Joined: 06 Feb 2007
Posts: 19
Location: Hyderabad

PostPosted: Mon Jun 18, 2007 12:15 pm    Post subject: Help needed on divide statement
Reply with quote

I have to include a field WS_DOL PIC9(16)V(4)in my working storage
But the mainframe that iam working on doesnot support for numeric fileds more than PIC 9(18)
so i had made it into a group item as follows
01 WS-REG-DOL.
05 WS-REG-DOL1 PIC 9(02).
05 WS-REG-DOL2 PIC 9(14)V9(04).


now i have another filed WS-R-DOL which is being calculated as
WS-R-DOL = WS-R-DOL + (WS-DOL * 1000) -- --(1)
( WS-R-DOL is initialised to zero)

now since WS-R-DOL is also being represented as a group item
as
01 WS-R-DOL.
05 WS-R-DOL1 PIC 9(06).
05 WS-R-DOL2 PIC 9(14)V9(04).



so now i have represented the equation (1) as

DIVIDE (((WS-R-DOL1 * (10 ** 14)) + WS-R-DOL2) +
(((WS-REG-DOL1 * (10 ** 14)) + WS-REG-DOL2) * 10000))
BY (10 ** 14)
GIVING WS-R-DOL1
REMAINDER WS-R-DOL2


But it is showing an error as u have to provide a dataitem after divide statement

Is there any other way out
Back to top
View user's profile Send private message
murmohk1

Senior Member


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

PostPosted: Mon Jun 18, 2007 12:20 pm    Post subject:
Reply with quote

Nithin,

COBOL doesn't perform automatic calculation of WS-R-DOL1 * (10 ** 14)) + WS-R-DOL2 in divide statement.

put all the computations with divide statement into temp variables and use them in divide statement like

divide temp-var1 by tempvar-2 .............


this temp-var1 should contains the result of (((WS-R-DOL1 * (10 ** 14)) + WS-R-DOL2) +
(((WS-REG-DOL1 * (10 ** 14)) + WS-REG-DOL2) * 10000))
Back to top
View user's profile Send private message
nithinlenin

New User


Joined: 06 Feb 2007
Posts: 19
Location: Hyderabad

PostPosted: Mon Jun 18, 2007 12:45 pm    Post subject:
Reply with quote

Hi Murali

Since the mainframes down;t support a data item greater than 9(18), i cannot copy (((WS-R-DOL1 * (10 ** 14)) + WS-R-DOL2) +
(((WS-REG-DOL1 * (10 ** 14)) + WS-REG-DOL2) * 10000))
this into a temp variable {this comes to more than PIC 9(18)}

with regards
Nithin
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Mon Jun 18, 2007 2:15 pm    Post subject:
Reply with quote

nithinlenin wrote:
Since the mainframes down;t support a data item greater than 9(18), i cannot copy (((WS-R-DOL1 * (10 ** 14)) + WS-R-DOL2) +
(((WS-REG-DOL1 * (10 ** 14)) + WS-REG-DOL2) * 10000))
this into a temp variable {this comes to more than PIC 9(18)}
Have you bothered to look at the manual?
Quote:
For binary items, the number of digit positions must range from 1 through 18 inclusive. For packed decimal and zoned decimal items the number of digit positions must range from 1 through 18, inclusive, when the ARITH(COMPAT) compiler option is in effect, or from 1 through 31, inclusive, when the ARITH(EXTEND) compiler option is in effect.
Back to top
View user's profile Send private message
nithinlenin

New User


Joined: 06 Feb 2007
Posts: 19
Location: Hyderabad

PostPosted: Mon Jun 18, 2007 2:25 pm    Post subject:
Reply with quote

Is it possible to use COmpute statement to give remainder like for example

Compute A/B giving C remainder D
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Mon Jun 18, 2007 2:35 pm    Post subject:
Reply with quote

nithinlenin wrote:
Is it possible to use COmpute statement to give remainder like for example
Compute A/B giving C remainder D
Again, have you bothered to look at the manual?
Back to top
View user's profile Send private message
Sandy Zimmer

Active Member


Joined: 13 Jun 2007
Posts: 826
Location: Wilmington, DE

PostPosted: Mon Jun 18, 2007 6:04 pm    Post subject:
Reply with quote

Hi!

Another thing that you should always consider is that you cannot divide by zero or you will abend. You can always check before you issue you divide statement to make sure the field is not zero. Don't say > zero because you may be dividing with a negative field. In your case, you won't because you have not signed your field. I always used the imperative "on size error". This will catch anything that is not within the boundaries such as zero. So issue a compute and on size error, do an error routine. Pack and sign all math fields. Something else to remember is that COBOL looks at ALL group items as alpha-numeric, so when initializing to zero, move to the individual fields within the group - you will end up with garbage if you init to the group level.
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 -913/-911 Deadlock during UPDATE stat... NoSleep319 DB2 5 Fri Nov 18, 2016 12:37 am
No new posts COBOL DB2 - CALL statement - high CPU... TS70363 DB2 15 Sun Sep 11, 2016 6:07 am
No new posts Converting NULL column into NOT NULL ... Raghu navaikulam DB2 5 Sat Aug 06, 2016 3:45 pm
This topic is locked: you cannot edit posts or make replies. Updating value of key using rewrite s... ParminderKumar COBOL Programming 4 Thu Aug 04, 2016 12:46 am
No new posts Help Needed with View Direct shailesh_do CA Products 2 Wed Jul 13, 2016 10:39 am


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