From the course: COBOL Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Comp-3 data types

Comp-3 data types - COBOL Tutorial

From the course: COBOL Essential Training

Start my 1-month free trial

Comp-3 data types

- [Instructor] It was a common practice in the 1980s to store numbers in what they call a packed decimal format, to save space on a file. In COBOL, we use the data usage clause comp-3 to indicate a packed decimal. Packed decimal format means that each byte of storage, except the low order byte can contain two decimal numbers. The low order byte contains one digit in the leftmost portion and the sign whether it's positive or negative in the rightmost portion. Here's an example representing the decimal number 21544. You can see it only takes up three bytes, which saves a lot of space. By using comp-3, we were able to compress numeric field into roughly half their size. This is especially useful in situations where we had to add a field to an existing file and there wasn't much space left to play with. If you convert an existing field to comp-3, you have additional space for other values. Comp-3 is also used to avoid rounding…

Contents