过度打孔的数字(Cobol中的Zoned-Decimal)来自旧打孔卡片,在那里他们在数字的最后一位数上打了过去.该格式通常用于Cobol.
由于既有Ascii和Ebcdic Cobol编译器,也有Zoned -Numeric的Ascii和EBCDIC版本.为了使它更复杂,US-Ebcdic(IBM037)的-0和+0值({}对于德语-Ebcdic(IBM273,它们是äü)而言是不同的,而在其他Ebcdic语言版本中则不同.
要成功处理,您需要知道:
如果数据是原始字符集,则可以计算符号
对于EBCDIC,数字十六进制代码是:
Digit 0 1 2 .. 9
unsigned: x'F0' x'F1' x'F2' .. x'F9' 012 .. 9
Negative: x'D0' x'D1' x'D2' .. x'D9' }JK .. R
Positive: x'C0' x'C1' x'C2' .. x'C9' {AB .. I
Run Code Online (Sandbox Code Playgroud)
对于US-Ebcdic Zoned这是转换字符串的java代码:
int positiveDiff = 'A' - '1';
int negativeDiff = 'J' - '1';
lastChar = ret.substring(ret.length() - 1).toUpperCase().charAt(0);
switch (lastChar) {
case '}' : sign = "-";
case '{' :
lastChar = '0';
break;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
lastChar = (char) (lastChar - positiveDiff);
break;
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
sign = "-";
lastChar = (char) (lastChar - negativeDiff);
default:
}
ret = sign + ret.substring(0, ret.length() - 1) + lastChar;
Run Code Online (Sandbox Code Playgroud)
对于德语-EBCDIC {}成为äü,对于其他EBCDIC语言,您需要查找适当的编码页面.
对于Ascii Zoned,这是java代码
int positiveFjDiff = '@' - '0';
int negativeFjDiff = 'P' - '0';
lastChar = ret.substring(ret.length() - 1).toUpperCase().charAt(0);
switch (lastChar) {
case '@':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
lastChar = (char) (lastChar - positiveFjDiff);
break;
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
sign = "-";
lastChar = (char) (lastChar - negativeFjDiff);
default:
}
ret = sign + ret.substring(0, ret.length() - 1) + lastChar;
Run Code Online (Sandbox Code Playgroud)
最后,如果你在EBCDIC工作,你可以计算它
sign = '+'
if (last_digit & x'F0' == x'D0') {
sign = '-'
}
last_digit = last_digit | x'F0'
Run Code Online (Sandbox Code Playgroud)
最后一个问题是小数点是不是存储在一个分区,十进制它们被假定.你需要看看Cobol-Copybook.
例如
if the cobol Copybook is
03 fld pic s99999.
123 is stored as 0012C (EBCDIC source)
but if the copybook is (v stands for assumed decimal point)
03 fld pic s999v99.
then 123 is stored as 1230{
Run Code Online (Sandbox Code Playgroud)
最好在Cobol中翻译!或使用Cobol翻译包.
有几个用于处理Cobol Data的商业软件包,它们往往很昂贵.有一些Java是一些可以处理Mainframe Cobol Data的开源软件包.
| 归档时间: |
|
| 查看次数: |
1885 次 |
| 最近记录: |