Page 1 of 1

converting packed decimal,binary to decimal without copybook

PostPosted: Wed Jun 26, 2013 12:37 pm
by rupa888
Hi,
I have a requirement to convert the packed decimal and binary fields in a file to decimal without using a copybook.In this case since i wont come to know about the starting position and length of packed decimal and binary field,first im converting everything into hexadecimal.Then trying to convert it into decimal.I dont have any problem in converting decimal,packed decimal,alphanumeric fields to hexadecimal and vice versa.But im having the problem in converting binary to decimal

For example,if im going to store 7561 as binary,When i convert it to hexadecimal,im getting as 1D89000C.So with this ebcdic represenation,how can i get 7561,please give me your suggestion?

Re: converting packed decimal,binary to decimal without copy

PostPosted: Wed Jun 26, 2013 4:51 pm
by Robert Sample
First, you need to understand that it is not possible to convert a file containing packed decimal and binary data without knowing the starting position and length of those fields. This does not mean that it is difficult -- it is IMPOSSIBLE. Why? Consider the bytes X'0097995C' stored in your file. The EBCDIC characters are a LOW-VALUE followed by 'pr*' -- perfectly valid characters. As a binary field, the value is 9935196. As a packed decimal field, the value is 97995. So which of those values do you use? Answer: unless you know whether those four bytes are binary or packed decimal or character from a copy book or a file layout, you cannot determine which way to interpret those bytes. All three ways are equally valid.

Second, your conversion mechanism looks suspect. 7561 decimal is 1D89 as hex data -- so where did the 000C come from?