COBOL Comp-5 doesn’t support Decimals why

In COBOL, the movement of data in computational fields is tricky. In fact, the COMP-5 data type saves internal storage, but it does not support decimals. I mean to say it stores only the integer part and truncates the decimal portion.

Let me put it precisely, you have a field defined with PIC 9(07)v99. And, you did move this field to comp-5.

COBOL Example on how to use COMP-5

01 My-data     PIC 9(07)v99 value 1234567.10.
01 Out-data    comp-5 or S9(07)v99 Comp-5.
MOVE My-data   to  Out-data.

The result will be: 1234567


The key point I want to share is Comp-5 stores only integer part and truncates decimal part.

Note: So, you cannot use comp-5 as S9(07)v99, but you can use as S9(09).

More details of COMP-5

  • Comp-5 stores the data in the form of Binary ( because of binary it doesn’t support decimals)
  • It has boundaries. It stores as 2/4/8 bytes internally
  • S9(1) to S9(4) => 2 bytes(half)
  • S9(5) to S9(9) ==> 4 bytes(full)
  • S9(10) to S9(18) ==> 8 bytes(double)
  • With or without ‘S’ you can define the Comp-5 data types


Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.