Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

packed decimal

Status
Not open for further replies.

dejfatman

Programmer
Jan 24, 2002
34
0
0
US
Hi, I am trying to read a binary file to update a table. The data is packed, and some of it is contained in one byte as packed decimal. Is there an quick way to convert this data to an integer?

x'20' should convert to 20, not 32.
 
This is an enteristing problem, but...

If you read the binary data into memory and analyze it one byte at a time, you can kind of do this:

Read Hex 20 into an intereger, which becomes Dec 32, so..

using the Hex function, IE Hex (32) returns 20.

If the number is less than 15, you end up with a number that is only one digit, so you can do something like this:

= right ("00" & hex (8), 2), which would return 08.

I don't think I have ever seen data stored like this, but let me know if I can help more.

ChaZ

Ascii dumb question, get a dumb Ansi
 
Did the data come from an IBM mainframe and was originally in EBCDIC format? If so, please give an example of the actual data.
 
If it is EBCDIC, that would be ideal, because it is just a straight conversion. But I do not recall EBCDIC being used to store hex values using only 0 - 9 and skipping A - F to convert to decimal.

Any body remember the reference to EBCDIC in the old Zork games?

Ascii dumb question, get a dumb Ansi
 
EBCDIC is a text coding like ANSI so I don't think it is relevant to this discussion. Packed decimal - can't remember exactly but obviously it is not ordinary hexadecimal. Apart from anything else it will have a decimal point in it somewhere. I seem to recall it has two numbers per byte, side by side. So 23 is stored in a byte but as 2 and 3 rather than (20+3).

Every mainframe has got utilities that transform data codings so the obvious thing is to run the file through one of those before you try to deal with it. Turn it into external format.

 
Wow. Blast from my cobol programming past. Packed decimal is not hex. BNPMike is correct. A quick and simple way is to write a little cobol program - packed in, decimal out.

Neil
 
Packed decimal on the IBM allows a large number to be stored in a smaller number of bytes. For example, an EBCDIC number of 2 bytes, such as, 99 would have a hex representation of F9F9 and after packing would be 099F. If this was negative it would be 099D. Depending on how it was packed a positive number could also be 099C which is normally the case. Since as was pointed out, Hex would not come into play in converting this number. You could convert this number by understanding the format of the packed decimal field. There is no explicit decimal in the number that is established by an input/output mask.
 
Well, I used Blorf's suggestion, and it works fine. The packed data is in only 1 byte and is unsigned. For example, when I grab a byte with 20 hex, vb reads it as 32. By Hex(variable name), it converts it back to 20, and I can put it in the table. Packed decimal is very common on mainframes, and that is what I primarily work on. I have been asked to develope some Access applications and I'm learning vb on the fly, so I appreciate the help.
 
Glad to hear my suggestion worked. Lots of reference to Cobal reminds me of a college class, where our instructer said "Drob the Obal, and Keep the C"



Ascii dumb question, get a dumb Ansi
 
Yeah, I have run into a few of those pompous types myself.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top