How to process mainframe numbers where "{" is the last character

500 views Asked by At

I have a one mainframe file data like as below

000000720000{

I need to parse the data and load into a hive table like below

72000

the above field is income column and "{" sign which denotes +ve amount datatype used while creating table income decimal(11,2)

in layout.cob copybook using INCOME PIC S9(11)V99

could someone help?

1

There are 1 answers

0
Hogstrom On

The number you want is 7200000 which would be 72000.00.

The conversion you are looking for is:

Positive numbers

{ = 0
A = 1
B = 2
C = 3
D = 4
E = 5
F = 6
G = 7
H = 8
I = 9

Negative numbers (this makes the whole value negative)

} = 0
J = 1
K = 2
L = 3
M = 4
N = 5
O = 6
P = 7
Q = 8
R = 9

Let's explain why.

Based on your question the issue you are having is when packed decimal data is unpacked UNPK into character data. Basically, the PIC S9(11)V2 actually takes up 7 bytes of storage and looks like the picture below.

You'll see three lines. The top is the character representation (missing in the first picture because the hex values do not map to displayable characters) and the lines below are the hexadecimal values. Most significant digit on top and least below.

enter image description here

Note that in the rightmost byte the sign is stored as C which is positive, to represent a negative value you would see a D.

When it is converted to character data it will look like this

enter image description here

Notice the C0 which is a consequence of the unpacking to preserve the sign. Be aware that this display is on z/OS which is EBCDIC. If the file has been transferred and converted to another code-page you will see the correct character but the hex values will be different.

Here are all the combinations you will likely see for positive numbers

enter image description here

and here for negative numbers

enter image description here

To make your life easy, if you see one of the first set of characters then you can replace it with the corresponding number. If you see something from the second set then it is a negative number.