Question

I have a flat file with below list of amounts, could you please tell me , what is the meaning of charectors which are ending with {,A,H,E,C,I,F and how can I make this below list of amount into two point decimal value something like 1234567.80 ?

12345678{
00484326A
00000210H
00000185A
00000077E
00000833C
00000255I
00000077E
00000039F
00000088A
00000000F
00000000A
00000100{

I have tried in below way, and I'm able to place "." between two substrings for all of them, for some reason I would like to try in some dynamic way to don't see some issues in my application.

string decimalstring = "12345678{";
decimalstring = decimalstring.Replace("{", "0");
int String1 = Convert.ToInt32(decimalstring.Substring(0, decimalstring.Length - 2));
string String2 = decimalstring.Substring(decimalstring.Length - 2, 2);
string Result = String1 + "." + String2;

Thank You,

Was it helpful?

Solution

The number looks like a Mainframe Cobol Zoned decimal number (certainly EBCDIC Cobol which would also include AS400 Cobol). The last digit represents the numeric sign and the last numeric digit digit (i.e { = +0; } = -0; A = 1; J=-1; B=2; k=-2 etc). The {, A, B are consecutive characters in the EBCDIC format.

  • {, A, B .. H represent positive 0 .. 9
  • }, J, K .. R represent negative 0 .. 9

So 123B is +1232 and 123K is -1232.

Biztalk almost certainly has code to decifer these numbers. Alternatively it could be easily translated to a normal number on the mainframe by a number of utilities (i.e. sort, easytrieve etc).

If you can not get the file translated, it is probably worth getting the Cobol Copybook.

Here is Java Code to decifer the number (It should not should not be to hard to convert to c#):

private static int positiveDiff = 'A' - '1';
private static int negativeDiff = 'J' - '1';

public static String fromZoned(String numZoned) {
    String ret;
    String sign = "";
    char lastChar;

    if (numZoned == null || numZoned.equals("") || numZoned.equals("-")) {
        // throw ...
        return "";
    }

    ret = numZoned.trim();
    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;

    return ret;
}

As a side note the format comes from the old Punch-Cards. To save space they over-typed the last numeric digit with the sign; Overtyping a 0 with a minus (or whatever they used) generates a } in EBCDIC etc).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top