过度冲孔数字(分区十进制Cobol 中)来自旧的打孔卡,它们在数字的最后一位数字上过度打孔。该格式在 Cobol 中常用。
因为两者都有Ascii and 埃布迪克·科博尔编译器,两者都有Ascii and EBCDIC分区数字的版本。更复杂的是,-0 和 +0 值({}对于 US-Ebcdic (IBM037) 与德语-Ebcdic (IBM273他们在哪里äü)并且在其他 Ebcdic 语言版本中又有所不同)。
要成功处理,您需要知道:
- 数据是否源自 Ebcdic 或 Ascii 系统
- if 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
For 美国Ebcdic这是转换字符串的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;
对于德语-EBCDIC {} 变为 äü,对于其他 EBCDIC 语言,您需要查找适当的编码页。
For Ascii这是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;
最后,如果您在 EBCDIC 工作,您可以这样计算
sign = '+'
if (last_digit & x'F0' == x'D0') {
sign = '-'
}
last_digit = last_digit | x'F0'
最后一个问题是小数点 are 未存储在分区中,假定为十进制。你需要看看 Cobol-Copybook。
e.g.
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{
最好用 Cobol 翻译!或使用 Cobol 翻译包。
有几种用于处理 Cobol 数据的商业包,它们往往很昂贵。
有一些 Java 和一些开源包可以处理大型机 Cobol 数据。