Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Problem regarding addition of two variables

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Problem regarding addition of two variables
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
Warnings : 1

New User


Joined: 28 Apr 2005
Posts: 99

PostPosted: Tue May 17, 2005 12:25 pm    Post subject: Re: Problem regarding addition of two variables
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Problem reading GTF trace output danik56 ABENDS & Debugging 7 Thu Mar 16, 2017 1:02 pm
No new posts ROUNDED Problem with COMPUTE statement shalem COBOL Programming 11 Thu Feb 09, 2017 8:16 pm
No new posts DB2 9.1.0 not move values to Host-Var... Miguel Fernandez DB2 8 Wed Jan 25, 2017 8:24 pm
No new posts DB2 9.1.0 not move values to Host-Var... Miguel Fernandez DB2 0 Wed Jan 25, 2017 8:23 pm
No new posts DB2 9.1.0 not move values to Host-Var... Miguel Fernandez DB2 0 Wed Jan 25, 2017 8:21 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us