# Json generation of comp-3 fields

**URL:** <https://community.openmainframeproject.org/t/json-generation-of-comp-3-fields/6271>\
**Category:** COBOL technical questions\
**Created:** [January 29, 2021, 3:05am UTC](https://community.openmainframeproject.org/t/json-generation-of-comp-3-fields/6271 "2021-01-29T03:05:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Poppins](https://avatars.discourse-cdn.com/v4/letter/p/df705f/32.png) [@Poppins](https://community.openmainframeproject.org/u/Poppins)\
**Post date:** [January 29, 2021, 3:05am UTC](https://community.openmainframeproject.org/t/json-generation-of-comp-3-fields/6271/1 "2021-01-29T03:05:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chris1](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@Chris1](https://community.openmainframeproject.org/u/Chris1)\
**Post date:** [February 3, 2021, 12:56am UTC](https://community.openmainframeproject.org/t/json-generation-of-comp-3-fields/6271/2 "2021-02-03T00:56:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Cecil](https://avatars.discourse-cdn.com/v4/letter/c/eb8c5e/32.png) [@Cecil](https://community.openmainframeproject.org/u/Cecil)\
**Post date:** [February 3, 2021, 5:55pm UTC](https://community.openmainframeproject.org/t/json-generation-of-comp-3-fields/6271/3 "2021-02-03T17:55:43Z")

</div>

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

[https://www.ibm.com/support/knowledgecenter/en/SSGMCP\_5.2.0/com.ibm.cics.ts.applicationprogramming.doc/datamapping/dfhws\_cobol2json.html](https://www.ibm.com/support/knowledgecenter/en/SSGMCP_5.2.0/com.ibm.cics.ts.applicationprogramming.doc/datamapping/dfhws_cobol2json.html)

---

<div class="post-metadata">

**Author:** ![normant](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@normant](https://community.openmainframeproject.org/u/normant)\
**Post date:** [February 4, 2021, 8:45am UTC](https://community.openmainframeproject.org/t/json-generation-of-comp-3-fields/6271/4 "2021-02-04T08:45:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Pavane](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Pavane](https://community.openmainframeproject.org/u/Pavane)\
**Post date:** [February 4, 2021, 3:21pm UTC](https://community.openmainframeproject.org/t/json-generation-of-comp-3-fields/6271/5 "2021-02-04T15:21:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![AndyDossett](https://avatars.discourse-cdn.com/v4/letter/a/edb3f5/32.png) [@AndyDossett](https://community.openmainframeproject.org/u/AndyDossett)\
**Post date:** [February 4, 2021, 9:01pm UTC](https://community.openmainframeproject.org/t/json-generation-of-comp-3-fields/6271/6 "2021-02-04T21:01:20Z")

</div>

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