View previous topic :: View next topic
|
Author |
Message |
gopinathmk
New User
Joined: 17 Nov 2006 Posts: 15
|
|
|
|
How to add 20 Digits number in Cobol?
For Ex:Suppose I have two numbers 10000000000000000000
and 10000000000000000000 and I want to add it.How can I do it in cobol?
SInce Max Allowable Pic Clause in cobol is 9(18).How It can be done? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
you could use the ARITH(EXTEND) option.
you can find info in COBOL documentation. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
SInce Max Allowable Pic Clause in cobol is 9(18).How It can be done? |
This is true only if ARITH(EXTEND) isn't being used. |
|
Back to top |
|
|
rajulan
New User
Joined: 11 Jan 2008 Posts: 66 Location: India
|
|
|
|
You can pass the arith(extend) compiler option thru parm parameter. Ohterwise you can code like below....
Process arith(extend),
Identification division.
------
-----
---
stop run.
Thanks,
Rajulan. |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
If you are restricted to an old compiler where the ARITH(EXTEND) option was not yet available, you could split the 20-digit numbers into "left" and "right" halves, add the right halves together, carry (if necessary) to the left halves, add the left halves, then concatenate the halves back together into your 20-digit number. Of course, since you are limited to 18 digits, you'd need to define that 20-digit number as alphanumeric. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Hi,
This is an interview question, 'am pretty sure Interviewer watned to know that do you know about "ARITH(EXTEND) option" or not..but the answer from Terry is over it..Excellent answer Big B... .
Rgards,
Ad |
|
Back to top |
|
|
Kmr.deepakcs
New User
Joined: 11 Oct 2013 Posts: 37 Location: India
|
|
|
|
Quote: |
If you are restricted to an old compiler where the ARITH(EXTEND) option was not yet available, you could split the 20-digit numbers into "left" and "right" halves, add the right halves together, carry (if necessary) to the left halves, add the left halves, then concatenate the halves back together into your 20-digit number. Of course, since you are limited to 18 digits, you'd need to define that 20-digit number as alphanumeric. |
I did not understand this...
can any body explain for me
thanks in advance.
Deepak |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
If you have an absurdly old compiler and you want to have a number with 20 significant digits, you can't, as ARITH(EXTEND) which allows for up to 31 digits is not supported.
So you have to split the number into two parts, neither of which exceeds 18 digits.
The likelihood of this situation arising is extremely limited, so I'll leave it at that. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
I didn't realise Turkish Lira was being utilised any more.... |
|
Back to top |
|
|
|