For Programmers: Free Programming Magazines  


Home > Archive > Cobol > May 2004 > COMP and COMP-3 fields









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author COMP and COMP-3 fields
Roger

2004-05-24, 2:30 am

Hi,

I would like to know what is the maximum and minimum value that can be
stored in the following declarations and how?

1. VAR1 PIC S9(03) COMP-3.
2. VAR2 PIC S9(04) COMP.
3. VAR3 PIC 9(03) COMP-3.
4. VAR4 PIC 9(04) COMP.

It would be of great help, if anybody can answer to me on this.

Thanks,
Sudhakar
Arnold Trembley

2004-05-24, 2:30 am



Roger wrote:
> Hi,
>
> I would like to know what is the maximum and minimum value that can be
> stored in the following declarations and how?
>
> 1. VAR1 PIC S9(03) COMP-3.
> 2. VAR2 PIC S9(04) COMP.
> 3. VAR3 PIC 9(03) COMP-3.
> 4. VAR4 PIC 9(04) COMP.
>
> It would be of great help, if anybody can answer to me on this.
>
> Thanks,
> Sudhakar


Assuming IBM mainframe COBOL, which seems likely given the COMP-3,
which is usually IBM packed decimal, making COMP likely to be IBM binary:

1. Integer values from -999 through +999.
2. Depends on the TRUNC compile-time option, but integer -9999
through +9999 for sure, possibly -32767 through +32767.
3. Integer values from 000 through 999.
4. Depends on the TRUNC compile-time option, but 0000 through 9999
for sure, possibly 00000 through 65535.

My answer for #2 is debatable, due to two's complement of the lowest
negative number.

I hope that helps!


--
http://arnold.trembley.home.att.net/


Binyamin Dissen

2004-05-24, 5:30 am

On 23 May 2004 22:16:30 -0700 sudhakarkreddy@yahoo.com (Roger) wrote:

:>I would like to know what is the maximum and minimum value that can be
:>stored in the following declarations and how?

:>1. VAR1 PIC S9(03) COMP-3.
:>2. VAR2 PIC S9(04) COMP.
:>3. VAR3 PIC 9(03) COMP-3.
:>4. VAR4 PIC 9(04) COMP.

:>It would be of great help, if anybody can answer to me on this.

Depends on how stored, and depends on compiler options.

1: -999:+999

2: (-32768/7 or -9999):(+32767 or +9999)

3: (-999 or 0):+999

4: (-32768/7 or o):(+32767 or +9999)

--
Binyamin Dissen <bdissen@dissensoftware.com>
http://www.dissensoftware.com

Director, Dissen Software, Bar & Grill - Israel
docdwarf@panix.com

2004-05-24, 6:30 am

In article <a2380f6f.0405232116.42ae7c30@posting.google.com>,
Roger <sudhakarkreddy@yahoo.com> wrote:
>Hi,
>
>I would like to know what is the maximum and minimum value that can be
>stored in the following declarations and how?


Please do your own homework.

DD

Michael Mattias

2004-05-24, 11:30 am

"Roger" <sudhakarkreddy@yahoo.com> wrote in message
news:a2380f6f.0405232116.42ae7c30@posting.google.com...
> I would like to know what is the maximum and minimum value that can be
> stored in the following declarations and how?
>
> 1. VAR1 PIC S9(03) COMP-3.
> 2. VAR2 PIC S9(04) COMP.
> 3. VAR3 PIC 9(03) COMP-3.
> 4. VAR4 PIC 9(04) COMP.
>


Text and graphic tutorial on COBOL data types:
http://www.flexus.com/ftp/cobdata.zip

--
Michael Mattias
Tal Systems, Inc.
Racine WI
mmattias@talsystems.com



Roger

2004-05-25, 2:30 am

Arnold Trembley <arnold.trembley@worldnet.att.net> wrote in message news:<t1gsc.21673$fF3.557761@bgtnsc05-news.ops.worldnet.att.net>...
> Roger wrote:
>
> Assuming IBM mainframe COBOL, which seems likely given the COMP-3,
> which is usually IBM packed decimal, making COMP likely to be IBM binary:
>
> 1. Integer values from -999 through +999.
> 2. Depends on the TRUNC compile-time option, but integer -9999
> through +9999 for sure, possibly -32767 through +32767.
> 3. Integer values from 000 through 999.
> 4. Depends on the TRUNC compile-time option, but 0000 through 9999
> for sure, possibly 00000 through 65535.
>
> My answer for #2 is debatable, due to two's complement of the lowest
> negative number.
>
> I hope that helps!


Thanks very much!!

I still have few questions, in the program i am debugging it is right
now able to store 18981 in the S9(04)comp field.

So, can you please let me know how do i find out what should be the
COMP declaration if i have to store a value of 45000....

Also i heard that in S9(04) we can store a value of up to 65635
eventhough we declared as s9(04) COMP....this is because COMP fields
do not care the sign field if it is having positive value...

Please clarify...

Thanks,
Sudhakar
William M. Klein

2004-05-25, 4:30 am

Again -
Please tell us the compiler you are using - and if you are on an IBM
mainframe, what setting you have for the TRUNC compiler option.

Without this information, we really cannot give you an accurate answer.

--
Bill Klein
wmklein <at> ix.netcom.com
"Roger" <sudhakarkreddy@yahoo.com> wrote in message
news:a2380f6f.0405242135.13040b61@posting.google.com...
> Arnold Trembley <arnold.trembley@worldnet.att.net> wrote in message

news:<t1gsc.21673$fF3.557761@bgtnsc05-news.ops.worldnet.att.net>...
>
> Thanks very much!!
>
> I still have few questions, in the program i am debugging it is right
> now able to store 18981 in the S9(04)comp field.
>
> So, can you please let me know how do i find out what should be the
> COMP declaration if i have to store a value of 45000....
>
> Also i heard that in S9(04) we can store a value of up to 65635
> eventhough we declared as s9(04) COMP....this is because COMP fields
> do not care the sign field if it is having positive value...
>
> Please clarify...
>
> Thanks,
> Sudhakar



JerryMouse

2004-05-25, 8:30 am

Roger wrote:
> Arnold Trembley <arnold.trembley@worldnet.att.net> wrote in message
> news:<t1gsc.21673$fF3.557761@bgtnsc05-news.ops.worldnet.att.net>...
>
> Thanks very much!!
>
> I still have few questions, in the program i am debugging it is right
> now able to store 18981 in the S9(04)comp field.
>
> So, can you please let me know how do i find out what should be the
> COMP declaration if i have to store a value of 45000....
>
> Also i heard that in S9(04) we can store a value of up to 65635
> eventhough we declared as s9(04) COMP....this is because COMP fields
> do not care the sign field if it is having positive value...
>
> Please clarify...
>
> Thanks,
> Sudhakar


1. Without fussing with the TRUNC option:

01 BigNumber pic 9(9) comp-4.*
01 Filler redefines BigNumber.
02 ignore-me pic x(2).
02 LittleNumber pic x(2).

Move 45000 to BigNumber.
Move LittleNumber to {storage area defined as X(2)}

on return
Move 0 to BigNumber
Move {storage area} to LittleNumber

Move BigNumber to Units-On-Hand (or whatever BigNumber represents)

----
*Assuming comp-4 on your machine is straight binary. With comp-5 on a PC,
the order of "ignore-me" and "LittleNumber" would be reversed.


Michael Mattias

2004-05-25, 9:30 am

"Roger" <sudhakarkreddy@yahoo.com> wrote in message
news:a2380f6f.0405242135.13040b61@posting.google.com...
>
> I still have few questions, in the program i am debugging it is right
> now able to store 18981 in the S9(04)comp field.
>
> So, can you please let me know how do i find out what should be the
> COMP declaration if i have to store a value of 45000....
>
> Also i heard that in S9(04) we can store a value of up to 65635
> eventhough we declared as s9(04) COMP....this is because COMP fields
> do not care the sign field if it is having positive value...
>
> Please clarify...


Did you read the tutorial I sent you to?

If you had, you would already know that the maximum "safe and supported"
value of *any* COBOL dataname with a USAGE clause other than COMP-1,
COMP-2, POINTER or PROCEDURE-POINTER is limited to the number of radix 10
digits defined in the PICTURE clause.

i.e., the maximum decimal value for....

LL VAR 1 PIC[TURE] [IS] [S]9(n)V9(m) USAGE COMP| COMP-3 | COMP-4 |
COMP-5| DISPLAY |PACKED-DECIMAL | BINARY

....is 'n' decimal digits before the decimal point and 'm' decimal digits
after. Period. (There's a "P" you can use to 'scale' these, but it sure does
not sound like you are ready for that... besides, in your application it is
not necessary).

All these replies dealing with the TRUNC option, taking advantage of a
particular compiler or piece of hardware, or redefinitions are "tricks" and
should not be used in the course of normal COBOL applications programming.

If you need to store the decimal value 45000, you may use any PICTURE and
USAGE clauses with five (5) or more decimal digits before the decimal point;
or you may use COMP-1 or COMP-2 (usually IEEE floats, and I don't recommend
the use of these due to the rounding problems inherent in floating point
data)


--
Michael Mattias
Tal Systems, Inc.
Racine WI
mmattias@talsystems.com










Howard Brazee

2004-05-25, 11:30 am


On 24-May-2004, sudhakarkreddy@yahoo.com (Roger) wrote:

> I still have few questions, in the program i am debugging it is right
> now able to store 18981 in the S9(04)comp field.
>
> So, can you please let me know how do i find out what should be the
> COMP declaration if i have to store a value of 45000....
>
> Also i heard that in S9(04) we can store a value of up to 65635
> eventhough we declared as s9(04) COMP....this is because COMP fields
> do not care the sign field if it is having positive value...


With my mainframe IBM compiler my pre-compiler stores database keys in fields
that are too large according to the CoBOL pictures. I use some redefines in a
called routine to actually access those numbers in full.

But you're safer to believe in the CoBOL standard. If your picture is S9(04),
believe it. Now your code will be portable, and it won't matter what compiler
options you have. (If you have a specialized need such as mine, come up with a
solution similar to mine).

If you want to know how much memory your S9(04) number takes up, that is a
different story.
Arnold Trembley

2004-05-25, 6:30 pm



Roger wrote:
> (snip)
>
> I still have few questions, in the program i am debugging it is right
> now able to store 18981 in the S9(04)comp field.
>
> So, can you please let me know how do i find out what should be the
> COMP declaration if i have to store a value of 45000....


Again, assuming an IBM mainframe COBOL compiler and a TRUNC(OPT)
compile time option, then PIC 9(4) COMP will probably work, but it is
a bit risky. Note carefully that the picture MUST BE unsigned. You
can never store 45000 into a PIC S9(4) COMP field because 45000 has
the leftmost bit ON, which will convert it to a negative number. With
S9(4) COMP, an assembler program can store values ranging from -32767
to +32767.

You would probably be better off with a picture clause that requires a
32-bit binary fullword, i.e. PIC S9(9) COMP.

>
> Also i heard that in S9(04) we can store a value of up to 65635
> eventhough we declared as s9(04) COMP....this is because COMP fields
> do not care the sign field if it is having positive value...


No, this will never be true. In a halfword (16 bits) the leftmost bit
is always the sign. So any binary representation greater than X'8000'
must be negative. The largest positive number you can represent in
PIC S9(4) COMP is X'7FFF' in hexadecimal, which is +32767 in decimal.

Negative numbers would be in the range X'8000' thru X'FFFF' in two's
complement form.

For an unsigned picture clause, i.e. PIC 9(4) COMP, the largest number
that can be stored is X'FFFF', which is +65535 decimal, but you could
never store a negative number into an unsigned COMP field.

Again, this is based only on my experience with IBM mainframe COBOL
compilers, with system 360/370 binary numbers in 16-bit halfwords.

I hope that helps!

--
http://arnold.trembley.home.att.net/


JerryMouse

2004-05-25, 9:30 pm

Howard Brazee wrote:
>
> But you're safer to believe in the CoBOL standard. If your picture
> is S9(04), believe it. Now your code will be portable, and it won't
> matter what compiler options you have. (If you have a specialized
> need such as mine, come up with a solution similar to mine).


Yeah, but that's why we experts get paid the big bucks. Imagine his case is
a parts warehouse and, after 20 years, the firm now has 9990 part numbers.
In a couple of ws, they'll add 15. The record is full, no spare bytes.
1000 more part numbers will suffice for five years.

What to do? Redefine the master file? Or subvert the standard?


Howard Brazee

2004-05-26, 11:30 am


On 25-May-2004, "JerryMouse" <nospam@bisusa.com> wrote:

>
> Yeah, but that's why we experts get paid the big bucks. Imagine his case is
> a parts warehouse and, after 20 years, the firm now has 9990 part numbers.
> In a couple of ws, they'll add 15. The record is full, no spare bytes.
> 1000 more part numbers will suffice for five years.
>
> What to do? Redefine the master file? Or subvert the standard?


My recommendation is redefine the master file. But that's after seeing lots
and lots of occasions where subversion was chosen. (IBM did a similar thing with
dates when 1960 rolled around!).

It's cheaper in the long run to do it right.
Harley

2004-05-29, 10:30 am

2 replies.

"Roger" <sudhakarkreddy@yahoo.com> wrote in message
news:a2380f6f.0405242135.13040b61@posting.google.com...
| Arnold Trembley <arnold.trembley@worldnet.att.net> wrote in message
news:<t1gsc.21673$fF3.557761@bgtnsc05-news.ops.worldnet.att.net>...
| > Roger wrote:
| > > Hi,
| > >
| > > I would like to know what is the maximum and minimum value that can be
| > > stored in the following declarations and how?
| > >
| > > 1. VAR1 PIC S9(03) COMP-3.
| > > 2. VAR2 PIC S9(04) COMP.
| > > 3. VAR3 PIC 9(03) COMP-3.
| > > 4. VAR4 PIC 9(04) COMP.
| > >
| > > It would be of great help, if anybody can answer to me on this.
| > >
| > > Thanks,
| > > Sudhakar
| >
| > Assuming IBM mainframe COBOL, which seems likely given the COMP-3,
| > which is usually IBM packed decimal, making COMP likely to be IBM
binary:

Comp-3 isn't exclusive to the IBM Mainframe, the Intel processors did, and
maybe still do support Packed Decimal.

| >
| > 1. Integer values from -999 through +999.
| > 2. Depends on the TRUNC compile-time option, but integer -9999
| > through +9999 for sure, possibly -32767 through +32767.
| > 3. Integer values from 000 through 999.
| > 4. Depends on the TRUNC compile-time option, but 0000 through 9999
| > for sure, possibly 00000 through 65535.

If you use COMP-5, the Compiler Option doesn't matter.

| >
| > My answer for #2 is debatable, due to two's complement of the lowest
| > negative number.
| >
| > I hope that helps!
|
| Thanks very much!!
|
| I still have few questions, in the program i am debugging it is right
| now able to store 18981 in the S9(04)comp field.
|
| So, can you please let me know how do i find out what should be the
| COMP declaration if i have to store a value of 45000....
|
| Also i heard that in S9(04) we can store a value of up to 65635
| eventhough we declared as s9(04) COMP....this is because COMP fields
| do not care the sign field if it is having positive value...

If you define the field as 9(4), the values range from 0 to 65635.
The S(ign) specification reduces the positive value by half, and allows
negative values.

If you really want to reduce the possibility of overflow use S9(8), or 9(8),
and COMP-5 if your compiler supports it.


|
| Please clarify...
|
| Thanks,
| Sudhakar


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com