sangiah
New User
Joined: 10 Jun 2005 Posts: 62
|
|
|
|
The following common COBOL data types:
Binary
Computational (comp)
Comp-1
Comp-2
Comp-3
Packed Decimal
Some compilers have comp-4 and comp-5 data types, usually to emulate a comp type of another system, like an IBM mainframe. There are other COBOL binary data types, such as index and pointer, but they are used internally in the program, and are not found in files, so are not of concern to us. Comp-3 is so common and so uniform across platforms that we have written a separate Tech Talk brief for it. See COBOL Comp-3 Packed Fields.
How the PIC and USAGE affect storage
Which data type a field uses for storage is determined by the "usage is" clause in the field definition. For example,
05 BALANCE-DUE PIC S9(6)V99 USAGE IS COMPUTATIONAL-3.
says to store the field in the computational-3 format. The "usage is" part is optional and generally left off, and "computational" can be abbreviated "COMP", so you will more commonly see this written:
05 BALANCE-DUE PIC S9(6)V99 COMP-3.
The number of bits, bytes, or words that are stored for any given field usually depends on the number of digits given in the COBOL PIC. For binary numbers, 8 bits, or 1 byte, will store unsigned values from 0 to 255 or signed values from -128 to +127. This is enough to store values up to two digits (99), but not up to three digits (999). So a PIC 9 or PIC 99 would require 1 byte, but a PIC 999 would require 2 bytes.
In addition, most compilers have some minimum requirements for comp storage. For example, the smallest unit of storage may be 2 bytes, so even if you specify PIC 9 (only 1 digit), the compiler will reserve two bytes. Also see Synchronization and Alignment below.
Floating point numbers, however, follow standard binary formats and as such their sizes are not determined by a PIC, and no PIC is used in the field definition.
Comp-3 stores two digits per byte, in BCD form.
Data Types
Typical storage for common data types is given below.
Binary
The COBOL standard specifies that this should be a binary data type, but the exact implementation is up to the vendor. Negative numbers are typically in 2's-complement.
Comp (Computational)
Comp (with no suffix) leaves the choice of the data type to the compiler writer. The intent of this data type is to make it the most efficient format on any given machine, which is usually some binary format. Because of this, comp varies greatly between platforms, more than most other types.
Comp-1
Comp-1 is usually a single precision floating point value, stored in 4 bytes. Many vendors follow the IEEE floating point standard, but IBM does not.
Comp-2
Comp-2 is usually a double precision floating point value, stored in 8 bytes. Many vendors follow the IEEE standard, but IBM does not.
Comp-3
Although comp-3 is "vendor specific", the format of comp-3 fields is almost universal across platforms, even on ASCII machines. Comp-3 stores data in a BCD -- binary coded decimal -- format with the sign after the least significant digit. Comp-3 is so common that we have written a separate Tech Talk brief about it. See COBOL Comp-3 Packed Fields.
Packed Decimal
This is the "official" BCD packed format of the COBOL standard. It is implemented as "comp-3". See comp-3, above.
Synchronization and Alignment
This topic is a bit involved for this tutorial, but you should be aware of it. When using binary storage (binary and comp), some compilers on some machines (computers) may require that a numeric field start on some boundary. For example, on a 32 bit machine, it may require that a comp field start on a 32 bit boundary.
If you specify a comp field in the middle of a record, and it doesn't happen to begin on a 32 bit (4 byte) boundary, the compiler will "align" it to a 32 bit boundary to "synchronize" it. What's actually stored in the file is not the same as the PICs on the layout. This is not a very common problem, partly because binary and comp fields are not very common in files, but you should be aware of it. |
|
MGIndaco
Active User
Joined: 10 Mar 2005 Posts: 432 Location: Milan, Italy
|
|
|
|
Ameershaik, this is not the correct forum but the answer is: Enter in your pds and at the top right you will see "Row 00001 of x"... when x is the total number of members.
Put your question in the correct forum and read the rule before a new post.
Thanks |
|