View previous topic :: :: View next topic

Author 
Message 
nithinlenin
New User
Joined: 06 Feb 2007 Posts: 19 Location: Hyderabad




hi
DIVIDE ((WSREGDOL1 * (10 ** 14)) + (WSREGDOL2)) * 10000
BY (10 ** 14)
GIVING WSRDOL1
REMAINDER WSRDOL2
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 




William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3158 Location: Tucson AZ




Strange question....
Assuming WSREGDOL2 is smaller than 10 to the 14th,
WSRDOL1 = WSREGDOL1 and WSRDOL2 = WSREGDOL2.
If WSREGDOL2 might be greater than 10 to the 14th, you could do a simple divide with remainder and add the giving to the above WSRDOL1. 

Back to top 


nithinlenin
New User
Joined: 06 Feb 2007 Posts: 19 Location: Hyderabad




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 WSREGDOL.
05 WSREGDOL1 PIC 9(02).
05 WSREGDOL2 PIC 9(14)V9(04).
now i have another filed WSRDOL which is being calculated as
WSRDOL = WSRDOL + (WSDOL * 1000)  (1)
( WSRDOL is initialised to zero)
now since WSRDOL is also being represented as a group item
as
01 WSRDOL.
05 WSRDOL1 PIC 9(06).
05 WSRDOL2 PIC 9(14)V9(04).
so now i have represented the equation (1) as
DIVIDE (((WSRDOL1 * (10 ** 14)) + WSRDOL2) +
(((WSREGDOL1 * (10 ** 14)) + WSREGDOL2) * 10000))
BY (10 ** 14)
GIVING WSRDOL1
REMAINDER WSRDOL2
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 


murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1439 Location: Bangalore,India




Nithin,
COBOL doesn't perform automatic calculation of WSRDOL1 * (10 ** 14)) + WSRDOL2 in divide statement.
put all the computations with divide statement into temp variables and use them in divide statement like
divide tempvar1 by tempvar2 .............
this tempvar1 should contains the result of (((WSRDOL1 * (10 ** 14)) + WSRDOL2) +
(((WSREGDOL1 * (10 ** 14)) + WSREGDOL2) * 10000)) 

Back to top 


nithinlenin
New User
Joined: 06 Feb 2007 Posts: 19 Location: Hyderabad




Hi Murali
Since the mainframes down;t support a data item greater than 9(18), i cannot copy (((WSRDOL1 * (10 ** 14)) + WSRDOL2) +
(((WSREGDOL1 * (10 ** 14)) + WSREGDOL2) * 10000))
this into a temp variable {this comes to more than PIC 9(18)}
with regards
Nithin 

Back to top 


William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3158 Location: Tucson AZ




nithinlenin wrote: 
Since the mainframes down;t support a data item greater than 9(18), i cannot copy (((WSRDOL1 * (10 ** 14)) + WSRDOL2) +
(((WSREGDOL1 * (10 ** 14)) + WSREGDOL2) * 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 


nithinlenin
New User
Joined: 06 Feb 2007 Posts: 19 Location: Hyderabad




Is it possible to use COmpute statement to give remainder like for example
Compute A/B giving C remainder D 

Back to top 


William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3158 Location: Tucson AZ




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 


Sandy Zimmer
Active Member
Joined: 13 Jun 2007 Posts: 826 Location: Wilmington, DE




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 alphanumeric, 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 


