Two Laptop Bag*
The moose likes Java in General and the fly likes Converting Zoned Decimal to Something Useable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Converting Zoned Decimal to Something Useable" Watch "Converting Zoned Decimal to Something Useable" New topic
Author

Converting Zoned Decimal to Something Useable

Theodore Casser
Ranch Hand

Joined: Mar 14, 2001
Posts: 1902

Heya, all.
I'm having a doozy of a problem and am beating my head against the wall. My employer needs me to convert and parse data from a file, and I'm semi-stuck.
I had been told the information was simply packed decimal numbers and began the conversions until I noticed really strange trends in the numbers. It would seem that they're really zoned decimals. As such, I'm obviously doing something wrong.
Does anyone have code handy to convert the zoned decimal data over to an integer?
Thanks in advance!


Theodore Jonathan Casser
SCJP/SCSNI/SCBCD/SCWCD/SCDJWS/SCMAD/SCEA/MCTS/MCPD... and so many more letters than you can shake a stick at!
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Try this: "Convert the EBCDIC zoned format decimal integer to ASCII on a byte for byte basis. ".


"JavaRanch, where the deer and the Certified play" - David O'Meara
Theodore Casser
Ranch Hand

Joined: Mar 14, 2001
Posts: 1902

Thanks, Cindy.
I don't know. I feel mildly stupid at the moment, because I'm obviously doing something wrong even with the example in front of me (I only know this because I continue to get nonsense numbers out).
The information for each zoned number I'm trying to retrieve is 6 bytes long in storage. From reading the code, I get the feeling I should be looping to have it go byte by byte and reassemble the number into a plain, old base-10 integer... but what I'm getting on the other end almost certainly is wrong.
I've enclosed the method I call to convert the number below - I've used the code referred to in the the prior response as the 'backbone', so I've not included it in my listing. As I've said, I'm obviously doing something wrong here....

I appreciate any help anyone can give me. I'm really feeling rather... well, overwhelmed and slow-witted at the moment.
JS Shirah
Greenhorn

Joined: Jan 23, 2003
Posts: 3
There is a toolkit for the AS/400 called JTOpen that contains data type conversion classes, including ones for EBCDIC packed and zoned decimal. It is open source and can be freely used. You may be able to use it as is ( the toolkit is almost all pure Java ) or modify the source. The specific classes of interest to you are:
com.ibm.as400.access.Class AS400PackedDecimal
com.ibm.as400.access.Class AS400ZonedDecimal
JTOpen source, documentation and binaries are available at:
http://www-124.ibm.com/developerworks/opensource/jt400/
Joe Sam
Joe Sam Shirah - http://www.conceptgo.com
conceptGO - Consulting/Development/Outsourcing
Java Filter Forum: http://www.ibm.com/developerworks/java/
Just the JDBC FAQs: http://www.jguru.com/faq/JDBC
Going International? http://www.jguru.com/faq/I18N
Que Java400? http://www.jguru.com/faq/Java400
Theodore Casser
Ranch Hand

Joined: Mar 14, 2001
Posts: 1902

I'll have to take a look at that - I did take a very quick glance when I began the current project and had thought it really not suited for what I'm trying to do, but you might be right in that being the better way to do it.
The other aspect, something that really didn't occur to me until Thursday evening (after COB, so I just now have dropped email to the program manager) is that I have no idea what the real data should look like. In essense, I could already be decoding it properly and not realize it.
Bah. I'll let you all know what I find and whether or not JTOpen or the earlier code manages to solve the problem, or if I end up having to write my own more detailed solution.
Theodore Casser
Ranch Hand

Joined: Mar 14, 2001
Posts: 1902

Okay, so I'm back with a new problem with regards to using the JTOpen API.
The text functions work great. Everything, in fact, works great... until I get to the numbers. For some strange reason, the numbers are packed into 6 byte clumps. I don't know why - they just are. Trying either AS400PackedBinary or AS400ZonedBinary gives me a NumberFormatException... and I cannot, offhand, think of how to get around this.
I'm still toying with ideas, but if anyone has thoughts, I'd appreciate having other opinions.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Converting Zoned Decimal to Something Useable