## converting packed decimal,binary to decimal without copybook

IBM's Command List programming language & Restructured Extended Executor

### converting packed decimal,binary to decimal without copybook

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?
rupa888

Posts: 21
Joined: Tue Sep 18, 2012 5:12 pm
Has thanked: 1 time
Been thanked: 0 time

### Re: converting packed decimal,binary to decimal without copy

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?
Robert Sample
Global moderator

Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times