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

Problem regarding addition of two variables


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
arunoday

New User


Joined: 17 May 2005
Posts: 18
Location: Bangalore

PostPosted: Tue May 17, 2005 10:13 am
Reply with quote

Hi All,

This is Arunoday from Bangalore. I have got the following problem -
my COBOL Compiler restricts me defining a PIC 9() variable not more than of size 18 (Including the decimal positions). Eg. I cannot define a variable of datatype PIC 9(18)V99. Now I have got two variables defines as follows , which I have to add and store the result in a third variable -

var1 PIC 9(17)V99
var2 PIC 9(17)V99

The problem is that the result is exceeding the 18-length limit. How can I define the third variable to store the addition result ?

Please help me.

Thanks
Back to top
View user's profile Send private message
Deepa.m

New User


Joined: 28 Apr 2005
Posts: 99

PostPosted: Tue May 17, 2005 12:25 pm
Reply with quote

var1 PIC 9(17)V99
var2 PIC 9(17)V99

EXCEEDS 18 BYTES. Do you mean 9(17)v9 ? were you able to declare var1 and var2 successfully as u mentioned.
Back to top
View user's profile Send private message
notonly4u

New User


Joined: 26 Apr 2005
Posts: 87
Location: Hyderabad

PostPosted: Tue May 17, 2005 2:06 pm
Reply with quote

You can Declare a variable of X(40) and store the value there, Since it is the OUTPUT variable.

Regards
Tanden
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Wed May 18, 2005 6:05 am
Reply with quote

Hi Arunoday,

I don't see how you can store your variables in a PIC 9(17)V99 field. That violates the 18 digit limit.

Anyway, you can try something like this:
Code:

01 fld-1x.
     02 dollars-1x  pic x(17).
     02 cents-1x    pic x(2).
01 fld-1n redefines fld-1x.
     02 dollars-1n  pic 9(17).
     02 cents-1n    pic 9(2).

Do the same for fld-2.

Add the $ for fld-1&2 into a 3rd fld of PIC 9(18).
Add the c for fld-1&2 into a 4rd fld of PIC 9(03).
If the cents fld (fld-4) is > 99 add 1 to fld-3.

Define a 5th field as PIC x(21).
Code:

move fld-3 to fld-5(1:18)
move '.'   to fld-5(1:19)
move fld-4 to fld-5(20:2)


It's not pretty, but it should work.










[/code]
Back to top
View user's profile Send private message
ajay_dheepak

New User


Joined: 12 May 2005
Posts: 32
Location: Chennai

PostPosted: Wed May 18, 2005 11:05 am
Reply with quote

Arunoday,

I agree the first part explanation of mmwife.

Code:

01 fld-1x.
02 dollars-1x pic x(17).
02 cents-1x pic x(2).
01 fld-1n redefines fld-1x.
02 dollars-1n pic 9(17).
02 cents-1n pic 9(2).


Use the definition for both var1 and var2. Later for performing addition do the decimal part addition first and then the whole number part. Remember when performing the addition for the whole number part the resultant sum should be in a PIC 9(18) field (as said by mmwife).

Try and let us know ur result
Back to top
View user's profile Send private message
somasundaran_k

Active User


Joined: 03 Jun 2003
Posts: 134

PostPosted: Wed May 18, 2005 6:31 pm
Reply with quote

The new Enterprise COBOL for z/OS supports upto 31 digits. If you have this, add ARITH(EXTEND) compiler option.

Code:

CBL ARITH(EXTEND)                                     
IDENTIFICATION DIVISION.



Regds
-Som
Back to top
View user's profile Send private message
arunoday

New User


Joined: 17 May 2005
Posts: 18
Location: Bangalore

PostPosted: Thu May 19, 2005 9:55 am
Reply with quote

Thanks mmwife and others ,

the solution with PIC X and redefinitons worked fine. One correction - the maximum digit limit is 18 only and so I cannot define PIC 9(17)v99. I can define only upto PIC 9(16)v99. Thanks for pointing out this also.

Bye


mmwife wrote:
Hi Arunoday,

I don't see how you can store your variables in a PIC 9(17)V99 field. That violates the 18 digit limit.

Anyway, you can try something like this:
Code:

01 fld-1x.
     02 dollars-1x  pic x(17).
     02 cents-1x    pic x(2).
01 fld-1n redefines fld-1x.
     02 dollars-1n  pic 9(17).
     02 cents-1n    pic 9(2).

Do the same for fld-2.

Add the $ for fld-1&2 into a 3rd fld of PIC 9(18).
Add the c for fld-1&2 into a 4rd fld of PIC 9(03).
If the cents fld (fld-4) is > 99 add 1 to fld-3.

Define a 5th field as PIC x(21).
Code:

move fld-3 to fld-5(1:18)
move '.'   to fld-5(1:19)
move fld-4 to fld-5(20:2)


It's not pretty, but it should work.










[/code]
Back to top
View user's profile Send private message
arunoday

New User


Joined: 17 May 2005
Posts: 18
Location: Bangalore

PostPosted: Thu May 19, 2005 9:59 am
Reply with quote

Hi Som

how can I know whether this option is available or not for my compiler ? because when I put your code it is giving following error- IGYDS1145-S and discarding the option.

Please let me know about its usage.

Thanks

somasundaran_k wrote:
The new Enterprise COBOL for z/OS supports upto 31 digits. If you have this, add ARITH(EXTEND) compiler option.

Code:

CBL ARITH(EXTEND)                                     
IDENTIFICATION DIVISION.



Regds
-Som
Back to top
View user's profile Send private message
somasundaran_k

Active User


Joined: 03 Jun 2003
Posts: 134

PostPosted: Thu May 19, 2005 7:00 pm
Reply with quote

arunoday
Check your compiler listing. This will tell you the version you are using. Also note that you should have the appopriate STEPLIB in the comipler step. Generally the library name is SYS1.SIGYCOMP. But it can have a different name too.

Regds
-Som
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Map Vols and Problem Dataset All Other Mainframe Topics 2
No new posts z/vm installation problem All Other Mainframe Topics 0
No new posts JCL with variables JCL & VSAM 1
No new posts Job scheduling problem. JCL & VSAM 9
No new posts Problem with IFTHEN=(WHEN=GROUP,BEGIN... DFSORT/ICETOOL 5
Search our Forums:

Back to Top