formatcobolbcdebcdiccomp-3

COBOL COMP-3 number format issue


I have a cobol "tape format" dump which has a mixture of text and number fields. I'm reading the file in C# as a binary array (array of byte). I have the copy book and the formats are lining up fine on the text fields. There are a number of COMP-3 fields as well. The data in those fields doesnt seem to match any BCD format. I know what the data should be and I have the raw bytes of the COMP-3. I tried converting to EBCDIC first which yielded no better results. Any thoughts on how a COMP-3 number can be otherwise internally stored? Below are three examples of the PIC, the raw data and the expected number. I know I have the field positions correct because there is alpha data on either side of the numbers and that all lines up correctly.

First Example: The PIC of the field is 9(9) COMP-3 There are 5 bytes to the data, the hex values are 02 01 20 91 22 The resulting data should be a date (00CCYYMMDD). This particular date should be 3-17-14.

Second Example: The PIC of the field is S9(3) COMP-3 There are 2 bytes to the data, the hex values are 0A 14 The resulting value should be between 900 and 999 My understanding is that the "S" means that the last nibble should be 0xC or 0xD to indicate + or -

Third Example: The PIC of the field is S9(15)V99 COMP-3 There are 9 bytes to the data, the hex values are 00 00 00 00 00 00 01 80 0C The resulting value should be 12.00

Ok so thanks to the people who responded as they pointed me in the right direction. This is indeed an ASCII/EBCDIC representation issue. The BCD is stored in EBCDIC. Using an ASCII to EBCDIC conversion table yields properly formatted BCD digits:

I used this link to map the data: http://shop.alterlinks.com/ascii-table/ascii-ebcdic-us.php

My data: 0A 14 Converted: 25 3C (turns out that 253 is a valid value, spec was wrong) C = +, all good

My data: 01 80 0C (excluding leading zeros) Converted: 01 20 0C 12.00 C = +, implied 2 digits in format, all good

My data: 02 01 20 91 22 Converted: 02 01 40 31 7F 2014/03/17 (F is unused nibble), all good


Solution

  • Ok so thanks to both people who responded as they pointed me in the right direction. This is indeed an ASCII/EBCDIC representation issue. The BCD is stored in EBCDIC. Using an ASCII to EBCDIC conversion table yields properly formatted BCD digits:

    I used this link to map the data: http://shop.alterlinks.com/ascii-table/ascii-ebcdic-us.php

    My data:    0A 14
    Converted:  25 3C  (turns out that 253 is a valid value, spec was wrong) C = +, all good
    
    My data:    01 80 0C  (excluding leading zeros)
    Converted:  01 20 0C  12.00  C = +, implied 2 digits in format, all good
    
    My data:    02 01 20 91 22
    Converted:  02 01 40 31 7F     2014/03/17  (F is unused nibble), all good
    

    Thanks again for the two above answers which led me in the right direction.