1

I have data that stored in the format using datatype called "Sign Embedded"

Sign Embedded

This data is similar to numeric character data, however, the sign will be embedded in the rightmost byte of the field.

that's what HELP said but I have no idea how to convert this to normal numeric char data

I have some examples of these data here

2698388x = -26983888
1665289w = -16652897
19200p = -192000
72119v = -721196

This is bitwise operation...I guess,but I don't know the exact algorithm.

I would appreciate if someone can help me figure this out :)

ps.this data is generated by COBOL program (though....doesn't matter)

Bruce Martin
  • 10,358
  • 1
  • 27
  • 38
Persk
  • 639
  • 2
  • 6
  • 15
  • any example with positive sign? – Dirk Nov 21 '14 at 09:55
  • positive value is stored as it is.I'm not sure if it untouch or it's touched but remain the same. – Persk Nov 21 '14 at 10:01
  • 1
    Is COBAL a typo? Look at the hex values of those numbers and letters. Supply name/vendor of compiler, OS involved, and where you got the message from please. This comes up too much, but this time it is obviously from an ASCII-based system. It really is best if the program producing the file does the work (which is easy in COBOL, nothing to it) and then you don't have to do much. Have a look here, for instance: http://stackoverflow.com/a/26945774/1927206 – Bill Woodger Nov 21 '14 at 10:25

2 Answers2

5

This is the Zoned decimal Format used by some Ascii Cobol compilers (Fujitsu, GNU-Cobol etc).

In a recent answer I provided java code for both mainframe and PC cobol compilers.

basically the last digit holds the sign and

          character     values       Hex
positive   @A => I     +0 => +9   40 => 49 
negative   PQ => Y     -0 => -9   50 => 59 or is it 70 => 79 (lower case)
unsigned   01 => 9      0 =>  9   30 => 39

The last or low nyble (4 bits) always give the decimal value, the first or high nyble give the sign.

I am not sure wether the negative numbers are represented by upper or lower case letters, would need to test.

Some compilers might not used the positive values.


Also in Cobol Zoned decimal, the decimal point is not stored, it is assumed

 if the Cobol Copybook is

     03 fld                 pic s99999.

 121 is stored as     0012A 

 if the Cobol Copybook is (no sign)

     03 fld                 pic 99999.

 121 is stored as     00121 

 but if the copybook is (v stands for assumed decimal point) 

    03 fld                  pic s999v99.

 then 123 is stored as 1230@  

So you Must have the COBOL copybook; It would be better to decode in Cobol or use a commercial package.

Most Open-Source Cobol interface packages concentrate on Mainframe EBCDIC Cobol. If java is an option

  • JRecord can handle the format (You need to specify one of the PC Dialects Fujitsu or OpenCobol). It also has an example program Cobol2Csv to convert from Cobol to Csv. The program Cobol2Csv is not Production ready.

Note: I am the author of JRecord.


To decode the number the code could be

lastDigit = uppercase(lastDigit);

switch (lastDigit) {
   case 'A' -> 'I': sign = '';  lastDigit = lastDigit - 'A' + '0'; break;
   case 'P' -> 'Y': sign = '-'; lastDigit = lastDigit - 'P' + '0'; break;
   case '0' -> '9': sign = '';
}

alternatively

digit = digit & x'0f';

always converts a character to a number in the range of 0 to 10 for both ebcdic or ascii numbers / zoned-decimal

Community
  • 1
  • 1
Bruce Martin
  • 10,358
  • 1
  • 27
  • 38
1

This is not an overpunch scheme that I recognize, but it's pretty clear that the pattern is

value letter hex
-0    p      70
-1    q      71
-2    r      72
-3    s      73
-4    t      74
-5    u      75
-6    v      76
-7    w      77
-8    x      78
-9    y      79
David Gorsline
  • 4,933
  • 12
  • 31
  • 36