COBOL COMP-3数字格式问题 [英] COBOL COMP-3 number format issue
问题描述
第一个例子:
PIC (9)COMP-3
数据有5个字节,十六进制值是02 01 20 91 22
结果数据应该是一个日期(00CCYYMMDD)。
第二个例子:
这个字段的PIC是S9(3)COMP-3
有2个字节的数据,十六进制值是0A 14
结果值应该在900和999
我的理解是,S意味着最后半字节应该是0xC或0xD到第三个例子:
这个字段的PIC是S9(15)V99 COMP-3
这个字段有9个字节数据,十六进制值是00 00 00 00 00 00 01 80 0C
结果值应该是12.00
好的,多谢那些回应的人指出我正确的方向。这确实是一个ASCII / EBCDIC表示问题。 BCD存储在EBCDIC中。使用ASCII到EBCDIC转换表可以得到格式正确的BCD数字:
我用这个链接来映射数据: http://shop.alterlinks.com/ascii-table/ascii-ebcdic-us.php
我的数据:0A 14转换:25 3C(原来253是一个有效值,spec是错误的)C = +,都很好
我的数据:01 80 0C(不包括前导零)转换:01 20 0C 12.00 C = +,隐含2位数字格式, :02 01 20 91 22转换:02 01 40 31 7F 2014/03/17(F是未使用的半字节),所有的都是好的
<好的,谢谢两位正在向我指出正确方向的人。这确实是一个ASCII / EBCDIC表示问题。 BCD存储在EBCDIC中。使用ASCII到EBCDIC转换表可以得到格式正确的BCD数字:
我用这个链接来映射数据: http://shop.alterlinks.com/ascii-table/ascii-ebcdic-us.php
我的数据:0A 14
转换:25 3C(原来253是一个有效值,spec是错的)C = +,所有好的
我的数据:01 80 0C(不包括前导零)
转换:01 20 0C 12.00 C = +,格式中暗示2位数,全部为好
我的数据:02 01 20 91 22
转换为:02 01 40 31 7F 2014/03/17(F为未用半字节),全部为
再次感谢上述两个答案,让我朝着正确的方向前进。
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
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.
这篇关于COBOL COMP-3数字格式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!