Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using COMP-1 In Cobol Program

Status
Not open for further replies.

klophockey

Programmer
May 25, 2016
41
US
I am not sure of what the bottom line issue is with respect to my using COMP-1 in a program.

I have a field defined as XYZ-FLD PIC 9(8) COMP-1.

I want to store the number 20110531 in the field. However, when I go to retrieve the value of the field I stored it says that it has a value of 9021. I have no idea what the 9021 even means.

The way I get the 9021 value is to read the record from the file and for that field bring it back into a S9(8) COMP-1 field, and then move it to a plain 9(8) field, and then display the 9(8) field so I can verify the data value.

The maximum number I can move into the field and be valid *same number in as it is out) is 32767.

Is there a Cobol compiler option that needs to be changed in order to store the larger number? If there is a compiler option that should be turned on, please let me know your specifics on that as well.

Thank you
 
A COMP-1 field is only 4 bytes long so can only store a maximum of hex "7FFF" which is 32767 in decimal.
If you need to store a larger number then you will need a different COMP- field.

If you google "Cobol COMP" fields you will find a lot of explanations of the COMP-1 to COMP-5 uses & size limitations.

Depending on what you are storing this for then either a COMP-2 / COMP-3 / PIC X(8) / PIC 9(8) will be best.
 
Welcome to Tek-Tips.

COMP-1 is not a standardized USAGE so what internal numeric representation is used depends entirely on the compiler you are using - and you did not specify that.

In general, I would advise against using non-standard numeric representations, because doing so can lead to unexpected behavior, such as you are experiencing.

Unless you have a genuine need to use COMP-1 (which you did not reveal), simply use the standard 9(8) to store your date. I strongly doubt that the data are stored in COMP-1 format (whatever that might be for the compiler you are using) in a file record.



Tom Morrison
Hill Country Software
 
Agree with k5tm. IT Dinosaurs like me remember that we had COMP fields to reduce storage requirements as well as speed computations. However, technological advances have made it such that disk, memory, and CPU cycles are considerably cheaper now. Unless you have a very specific need to use COMP-1, or any kind of COMPutational data type, I agree with k5tm that you should use the standard decimal 9 format.

==================================
adaptive uber info galaxies (bigger, better, faster, and more adept than cognitive agile big data clouds)


 
Yea, all those little memory donuts were hand wired, installed in refrigerator-sized cabinets that were lined up in a large room with a raised floor, cooled by huge air conditioning units. Now you can hold that amount of memory in the palm of your hand.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Iron donuts.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top