View previous topic :: View next topic
|
Author |
Message |
arunoday
New User
Joined: 17 May 2005 Posts: 18 Location: Bangalore
|
|
|
|
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 |
|
|
Deepa.m
New User
Joined: 28 Apr 2005 Posts: 99
|
|
|
|
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 |
|
|
notonly4u
New User
Joined: 26 Apr 2005 Posts: 87 Location: Hyderabad
|
|
|
|
You can Declare a variable of X(40) and store the value there, Since it is the OUTPUT variable.
Regards
Tanden |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
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 |
|
|
ajay_dheepak
New User
Joined: 12 May 2005 Posts: 32 Location: Chennai
|
|
|
|
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 |
|
|
somasundaran_k
Active User
Joined: 03 Jun 2003 Posts: 134
|
|
|
|
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 |
|
|
arunoday
New User
Joined: 17 May 2005 Posts: 18 Location: Bangalore
|
|
|
|
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 |
|
|
arunoday
New User
Joined: 17 May 2005 Posts: 18 Location: Bangalore
|
|
|
|
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 |
|
|
somasundaran_k
Active User
Joined: 03 Jun 2003 Posts: 134
|
|
|
|
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 |
|
|
|