![]() |
Binary or COMP Format Description and Discussion |
| When technology complements business | Copyright © 1987-2012 SimoTime Enterprises All Rights Reserved |
| The SimoTime Home Page |
This document provides an overview (description and discussion of content and size) of binary (or COMP) fields as they are implemented on an IBM Mainframe or a Micro Focus Wintel or Unix environment.
Note: The items in this document are appropriate for applications that are written in COBOL, Mainframe Assembler (HLASM) or PL/I. The IBM Mainframe architecture drove many of the numeric formats that existed in the early ANSI specifications for COBOL and have been carried forward to the current COBOL ANSI specifications.
The following table shows the structure of a three digit numeric field using the Binary format that is used on an IBM Mainframe System(i.e. the COBOL syntax would be USAGE IS COMP). The field contains a value of one-hundred-twenty-three (or 123). Since the binary format stores the number as an actual binary value the field will only be two (2) bytes in length.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Note: 1 A binary field that is defined as "Unsigned" (i.e. PIC 999) is an implied positive value. A two (2) byte unsigned, binary field may contain a range of implied positive values from 0 to 65,535. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Note: 2 A binary field that is defined as "Signed" (i.e. PIC S999) will use the high-order, leftmost bit as the sign. A zero (0) is a positive sign and a one (1) is a negative sign. A two (2) byte signed, binary field may contain a range of values from -32,767 to +32,767. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| The BINARY Format for a Numeric Field |
The creation and processing of COMP or BINARY data on a Windows or UNIX platform must be done in the same manner as the mainframe. On the mainframe COMP or BINARY fields must be 2, 4, or 8 bytes in length (the mainframe was originally a half-word, full-word and double-word centric system). On Linux, UNIX or Windows (using Micro Focus COBOL with Net Express or Server Express) the COMP or BINARY fields may be 1 through 8 bytes in length.
Note: The syntax for COBOL is "USAGE IS COMPUTATIONAL". However, this is usually abbreviated to COMP or may be coded as BINARY.
Notice the following, the record layout for the Item Master File contains two (2) COMP or BINARY fields. These fields are defined as PIC 9(7) and may contain values from zero (0) through 9,999,999 or the binary values of x'000000' through x'98967F' which may be contained in a three (3) byte binary field.
Herein is the problem, on the EBCDIC-encoded, half-word, full-word, double-word, mainframe environment the fields would be allocated with an actual length of four (4) bytes for a binary field. For the Micro Focus, ASCII-encoded, byte-oriented environment the fields would be allocated with an actual length of three (3) bytes for a binary field.
01 ITEM-RECORD.
05 ITEM-NUMBER PIC X(12).
05 ITEM-DATA.
10 ITEM-DESCRIPTION PIC X(48).
10 ITEM-QTY-ONHAND PIC 9(7) COMP.
10 ITEM-QTY-ALLOCATED PIC 9(7) COMP.
10 ITEM-UNIT-OF-MEASURE PIC X(16).
10 ITEM-COST PIC S9(7)V9(2) COMP-3.
10 ITEM-PRICE PIC S9(7)V9(2) COMP-3.
10 ITEM-LADATE PIC X(8).
10 ITEM-LATIME PIC X(8).
10 ITEM-TOKEN PIC X(3).
10 ITEM-D-CODE-1 PIC X.
10 ITEM-D-PERCENT-1 PIC S9(3)V9(4).
10 ITEM-D-CODE-2 PIC X.
10 ITEM-D-PERCENT-2 PIC S9(3)V9(4).
10 ITEM-D-CODE-3 PIC X.
10 ITEM-D-PERCENT-3 PIC S9(3)V9(4).
10 FILLER PIC X(375).
The solution to this problem for the Micro Focus environment is to use the IBMCOMP and NOTRUNC directives when compiling the programs. This will enforce the mainframe rules for COMP or BINARY fields and the field lengths will be the same as the mainframe.
An alternative solution is to modify the copy file and change the PIC 9(7) to PIC 9(8). However, this solution requires a source code change and is not recommended during the first phase of a data migration.
The following table shows the COBOL picture clause, the number of digits, the length of a packed field, the length of a binary (COMP) field for an IBM Mainframe and the length of a binary field for the Linux, UNIX and Windows (LUW) environments running Micro Focus COBOL.
The differences in field (or data string) length are high-lighted in RED .
| COBOL Picture Clause |
Number of Digits |
Length Packed |
Length Binary (IBM) |
Length Binary (Micro Focus) |
| PIC 9 | 1 | 1 | 2 | 1 |
| PIC 99 | 2 | 2 | 2 | 1 |
| PIC 999 | 3 | 2 | 2 | 2 |
| PIC 9(4) | 4 | 3 | 2 | 2 |
| PIC 9(5) | 5 | 3 | 4 | 3 |
| PIC 9(6) | 6 | 4 | 4 | 3 |
| PIC 9(7) | 7 | 4 | 4 | 3 |
| PIC 9(8) | 8 | 5 | 4 | 4 |
| PIC 9(9) | 9 | 5 | 4 | 4 |
| PIC 9(10) | 10 | 6 | 8 | 5 |
| PIC 9(11) | 11 | 6 | 8 | 5 |
| PIC 9(12) | 12 | 7 | 8 | 5 |
| PIC 9(13) | 13 | 7 | 8 | 6 |
| PIC 9(14) | 14 | 8 | 8 | 6 |
| PIC 9(15) | 15 | 8 | 8 | 7 |
| PIC 9(16) | 16 | 9 | 8 | 7 |
| PIC 9(17) | 17 | 9 | 8 | 8 |
| PIC 9(18) | 18 | 10 | 8 | 8 |
It is important to note that Micro Focus Mainframe Express supports the mainframe format for binary (or COMP) fields. This is accomplished by pre-setting the compiler directives to force this behavior. The compiler directives are IBMCOMP and NOTRUNC. These directives may also be used with Net Express and must be configured manually since the default for Net Express is to allow binary fields to be any length.
The purpose of this document is to provide an overview of binary formats for numeric data strings or fields. This document may be used as a tutorial for new programmers or as a quick reference for experienced programmers. In the world of programming there are many ways to solve a problem. This document and the links to other documents are intended to provide a choice of alternatives.
Permission to use, copy, modify and distribute this software, documentation or training material for any purpose requires a fee to be paid to SimoTime Enterprises. Once the fee is received by SimoTime the latest version of the software, documentation or training material will be delivered and a license will be granted for use within an enterprise, provided the SimoTime copyright notice appear on all copies of the software. The SimoTime name or Logo may not be used in any advertising or publicity pertaining to the use of the software without the written permission of SimoTime Enterprises.
SimoTime Enterprises makes no warranty or representations about the suitability of the software, documentation or learning material for any purpose. It is provided "AS IS" without any expressed or implied warranty, including the implied warranties of merchantability, fitness for a particular purpose and non-infringement. SimoTime Enterprises shall not be liable for any direct, indirect, special or consequential damages resulting from the loss of use, data or projects, whether in an action of contract or tort, arising out of or in connection with the use or performance of this software, documentation or training material.
This section includes links to documents with additional information that is beyond the scope and purpose of this document. The first sub-section requires an internet connection, the second sub-section references locally available documents.
The following links will require an internet connect.
A good place to start is The SimoTime Home Page for access to white papers, program examples and product information.
Explore The Numbers Connection in the SimoTime Library for more examples of programs and documentation that describe and demonstrate techniques for understanding and processing the various numeric field formats used in a mainframe environment.
Explore The ASCII and EBCDIC translation tables. These tables are provided for individuals that need to better understand the bit structures and differences of the encoding formats.
Explore The File Status Return Codes to interpret the results of accessing VSAM data sets and QSAM files.
Explore The Micro Focus Web Site for more information about products and services available from Micro Focus.
Note: You must be attached to the Internet to download a Z-Pack or view the list.
The following links may be accessible without an internet connection.
Note: A SimoTime License is required for the items to be made available on a local server.
| Numeric Type | Description |
| Zoned Decimal | This document describes the zoned-decimal format. This is coded in COBOL as USAGE IS DISPLAY and is the default format if the USAGE clause is missing. Note: This is the slowest performer and uses the most storage space but is easiest to display on a screen or print to a printer. This encoding scheme may be unsigned (implied positive) or signed. This type of field will require special handling for the sign position when migrating from a mainframe (EBCDIC) to a Micro Focus (ASCII) environment. |
| Packed Decimal | This document describes the packed-decimal format. This is coded in COBOL as USAGE IS COMPUTATIONAL-3 and is usually coded in its abbreviated form of COMP-3. Note: The mainframe can perform arithmetic functions with this data format at the hardware (or micro-code) level. This type of encoding scheme was primarily used to save storage space. This encoding scheme may be unsigned (implied positive) or signed. When migrating from a mainframe (EBCDIC) to a Micro Focus (ASCII) environment this type of field should be left in its original format since this will be supported in the new environment. |
| Binary | This document describes the binary format. This is coded in COBOL as USAGE IS COMPUTATIONAL and is usually coded in its abbreviated form of COMP. This may also be coded with the keyword BINARY. Note: This format will save storage space but was primarily used for performance. Register arithmetic uses this format. This encoding scheme may be unsigned (implied positive) or signed. When migrating from a mainframe (EBCDIC) to a Micro Focus (ASCII) environment this type of field should be left in its original format since this will be supported in the new environment. |
| Edited Numeric | This document describes the edited numeric format. This is coded in COBOL using an edit mask in the picture clause. An example would be PIC ZZZ.99+. Note: This type of field is used for numbers that are to be displayed or printed and should be all text characters. This filed should be converted using standard conversion tables. |
| Floating Point | This format is used when a high level of precision is required or very large numbers are required. On the mainframe the default is to use the IBM 370 Floating Point Arithmetic. On Windows or UNIX using Micro Focus the default is to use the IEEE Standard for Floating Point Arithmetic. The IEEE standard provides a higher level of precision than 370. However, 370 provides for larger numbers by providing less precision. |
| numbug01 | The challenge with this program is that it is expected to process the various numeric items in the same manner as the mainframe. For example, a zoned-decimal field that contains leading spaces should not cause an ABEND (i.e. 163 error on Micro Focus) but should treat the leading spaces as zeroes and complete the arithmetic calculation. However, a packed-decimal field that contains non-numeric values would issue a S0C7 (referred to as a sock-seven) on the mainframe and should issue a 163 error in the Micro Focus environment. |
| numprt01 | Printing numeric fields, especially packed-decimal or binary (i.e. COMP-3 or COMP) requires special consideration. Also, signed, zoned-decimal fields will require special consideration. Most numeric fields will require some sort of editing before printing. This suite of programs provides examples of how a COBOL program may be used to properly print (or display) numeric fields. |
Explore The File Status Return Codes to interpret the results of accessing VSAM data sets and QSAM files.
Check out The SimoTime Glossary for a list of terms and definitions used in the documents provided by SimoTime.
This document was created and is maintained by SimoTime Enterprises.
If you have any questions, suggestions, comments or feedback please call or send an e-mail to: helpdesk@simotime.com
We appreciate hearing from you.
Founded in 1987, SimoTime Enterprises is a privately owned company. We specialize in the creation and deployment of business applications using new or existing technologies and services. We have a team of individuals that understand the broad range of technologies being used in today's environments. This includes the smallest thin client using the Internet and the very large mainframe systems. There is more to making the Internet work for your company's business than just having a nice looking WEB site. It is about combining the latest technologies and existing technologies with practical business experience. It's about the business of doing business and looking good in the process. Quite often, to reach larger markets or provide a higher level of service to existing customers it requires the newer Internet technologies to work in a complementary manner with existing corporate mainframe systems.
Whether you want to use the Internet to expand into new market segments or as a delivery vehicle for existing business functions simply give us a call or check the web site at http://www.simotime.com
| Return-to-Top |
| Binary or COMP Format, a Description and Discussion |
| Copyright © 1987-2012 SimoTime Enterprises All Rights Reserved |
| When technology complements business |
| http://www.simotime.com |