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

How to add 20 Digits number in Cobol?


IBM Mainframe Forums -> Mainframe Interview Questions
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
gopinathmk

New User


Joined: 17 Nov 2006
Posts: 15

PostPosted: Tue Jan 20, 2009 3:42 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Jan 20, 2009 4:01 pm
Reply with quote

you could use the ARITH(EXTEND) option.

you can find info in COBOL documentation.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Jan 20, 2009 5:56 pm
Reply with quote

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
View user's profile Send private message
rajulan

New User


Joined: 11 Jan 2008
Posts: 66
Location: India

PostPosted: Tue Jan 27, 2009 12:45 pm
Reply with quote

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
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Wed Jan 28, 2009 11:51 am
Reply with 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.
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Wed Jan 28, 2009 1:07 pm
Reply with quote

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... icon_smile.gif.

Rgards,
Ad
Back to top
View user's profile Send private message
Kmr.deepakcs

New User


Joined: 11 Oct 2013
Posts: 37
Location: India

PostPosted: Sat Nov 02, 2013 11:42 am
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Sat Nov 02, 2013 2:16 pm
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Sat Nov 02, 2013 6:24 pm
Reply with quote

I didn't realise Turkish Lira was being utilised any more.... icon_razz.gif
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 -> Mainframe Interview Questions

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Substring number between 2 characters... DFSORT/ICETOOL 2
Search our Forums:

Back to Top