Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Using COMP-1 In Cobol Program

Using COMP-1 In Cobol Program

Using COMP-1 In Cobol Program

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

RE: Using COMP-1 In Cobol Program

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.

RE: Using COMP-1 In Cobol Program

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

RE: Using COMP-1 In Cobol Program

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)

RE: Using COMP-1 In Cobol Program

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.


glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Using COMP-1 In Cobol Program

Mmmm, donuts!

RE: Using COMP-1 In Cobol Program

Iron donuts.


glassesJust traded in my OLD subtlety...
for a NUance!tongue

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close