Binary field
A COBOL number stored as a binary integer, written with USAGE COMP, COMP-4, BINARY or COMP-5.
Also written COMP, COMP-4, COMP-5, BINARY, halfword, fullword
A binary field holds a number as a binary integer, the format the processor uses most naturally. In COBOL you ask for one with USAGE COMP, COMP-4 or BINARY, which all mean the same, or COMP-5.
The size depends on the number of digits in the PICTURE. Up to 4 digits, as in PIC S9(4) COMP, takes 2 bytes, called a halfword. Five to 9 digits takes 4 bytes, a fullword. Ten to 18 digits takes 8 bytes. COMP-5 uses the full range the bytes can hold, rather than the number of digits in the PICTURE.
Binary fields are used for counters, subscripts, lengths and anything passed to other languages or system services. DB2 columns of type SMALLINT and INTEGER map to them, which is why DCLGEN produces them.
They are not readable in browse or edit. A binary field looks like random characters, and you need to view it in hexadecimal to see the value. For money and other decimal amounts, packed decimal is the usual choice instead.
Where can I learn this hands-on?
Right here, at ZedBank. You take a junior job at a simulated bank and learn each part of the work by doing it, with Zed beside you. There's nothing to install.
Start at ZedBankRelated
- Packed decimalA compact way of storing numbers, two digits per byte, used heavily for amounts in business records.
- PICTURE clauseThe COBOL declaration that says what kind of data a field holds and how long it is, written as PIC.
- DATA DIVISIONThe part of a COBOL program that declares every record layout and variable it will use.
- Zoned decimalThe default way COBOL stores numbers: one digit per byte, readable as text, with the sign hidden in the last byte.
- EBCDICThe character encoding mainframes use, where letters and numbers are stored as different byte values than on a laptop.
- DCLGENA tool that generates COBOL declarations matching a DB2 table, so the program's fields line up with the columns.