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

Author Message
nithinlenin

New User

Joined: 06 Feb 2007
Posts: 19

 Posted: Sun Jun 17, 2007 12:33 pm    Post subject: Represnt the statement using COMPUTE instead of DIVIDE 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

William Thompson

Global Moderator

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

 Posted: Sun Jun 17, 2007 4:52 pm    Post subject: 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.
nithinlenin

New User

Joined: 06 Feb 2007
Posts: 19

 Posted: Mon Jun 18, 2007 12:15 pm    Post subject: Help needed on divide statement 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
murmohk1

Senior Member

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

 Posted: Mon Jun 18, 2007 12:20 pm    Post subject: 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))
nithinlenin

New User

Joined: 06 Feb 2007
Posts: 19

 Posted: Mon Jun 18, 2007 12:45 pm    Post subject: 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
William Thompson

Global Moderator

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

Posted: Mon Jun 18, 2007 2:15 pm    Post subject:

 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.
nithinlenin

New User

Joined: 06 Feb 2007
Posts: 19

 Posted: Mon Jun 18, 2007 2:25 pm    Post subject: Is it possible to use COmpute statement to give remainder like for example Compute A/B giving C remainder D
William Thompson

Global Moderator

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

Posted: Mon Jun 18, 2007 2:35 pm    Post subject:

 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?
Sandy Zimmer

Active Member

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

 Posted: Mon Jun 18, 2007 6:04 pm    Post subject: 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.
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics COBOL - EXIT statement weird behavior anthony.pangestu COBOL Programming 0 Fri Oct 27, 2017 9:57 am WER268A OUTREC STATEMENT : SYNTAX E... frozenblood87 SYNCSORT 12 Sat Aug 26, 2017 9:45 pm Suppress value reported by BREAK in D... Learncoholic DFSORT/ICETOOL 3 Wed Aug 16, 2017 6:03 pm ON 2 AND EVERY 1 - Statement ??? UmeySan COBOL Programming 2 Tue Jul 25, 2017 1:20 pm SORT trick needed bshkris SYNCSORT 6 Tue May 02, 2017 4:35 am

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us