Json generation of comp-3 fields

Hello I’m a mainframer whose trying to do something new, but can’t seem to get this working,
the program is cobol and I’m using the cobol ‘generate’ command that works unless the record being generated contains comp-3 fields.
has anyone done this, does anyone know if this can be done? I keep getting an oc7.
I am using a DB2 record and record layout

In your select statement from DB2, you can receive the comp-3 field as non-decimal. integer or if you need decimal places, then character.

See the following link for mapping between a COBOL pic and a JSON definition:


It’s a long time since I wrote any COBOL and I have no experience of the generate statement, but I can tell you a bit about comp-3 fields that may help.
Comp-3 is also known as packed decimal. It was widely used in the days when memory and disk space were enormously expensive. It was a recognition that storing numbers was wasteful. For example, with USAGE DISPLAY the number 123 would be represented in hexadecimal as x’F1F2F3’. The hex representation of the same number in comp-3 would be ‘123F’. This reduces the storage space required to hold the number from three to two bytes.
(In essence, the sign is removed from each of the digits and a single sign appears at four rightmost bits the ‘packed’ number).
Numbers compressed in this way need to be moved to DISPLAY fields to be printable. I suspect that the 0C7 is being produced because the Generate statement either doesn’t recognise (or can’t handle) packed decimal.

1 Like

Negative sign is “D” so -123 would be hex “123D”. C is also positive, so “123C” is the same as “123F”

Have you defined your comp-3 fields as signed, e.g. S9(9)V99?