× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Thanks Joe and Mark -
First a little background:  The field is 4 bytes long packed, 7 unpacked.  It's 
an integer value, so no decimals (Although I have dollar amounts to deal with 
if I get past this).  I've tried the below code three different ways: 
1) Reading the file that had been converted to ASCII
2) Reading the binary file, with encoding set to "IBM1047"
3) Reading the binary file, with no encoding.
Here's the code I'm using:
String strValue = rec.substring (from-1, to);
System.out.println("strValue = " + BinaryConverter.bytesToString 
(strValue.getBytes () ));
AS400PackedDecimal pd = new AS400PackedDecimal (4,0);
double pdNum = pd.toDouble (BinaryConverter.stringToBytes (strValue));
System.out.println ("Packed Decimal = " + pdNum);
And the result (From all three attempts) : 
strValue = 0000000C
java.lang.NumberFormatException
        at 
com.ibm.as400.access.BinaryConverter.stringToBytes(BinaryConverter.java:531)
        at 
com.ibm.as400.access.BinaryConverter.stringToBytes(BinaryConverter.java:485)
        at 
com.ibm.as400.access.BinaryConverter.stringToBytes(BinaryConverter.java:478)
        at gcs.ParseCAT_GLS.parseRecord(ParseCAT_GLS.java:142)
        at gcs.ParseCAT_GLS.parseRecord(ParseCAT_GLS.java:160)
        at gcs.ParseCAT_GLS.parseRecord(ParseCAT_GLS.java:160)
        at gcs.ParseCAT_GLS.getNextRecord(ParseCAT_GLS.java:117)
        at gcs.TransformCAT_GLS.main(TransformCAT_GLS.java:44)
Exception in thread "main" 
I thought about trying to create a SequentialFile object along with a 
RecordFormat object, but that requires a connection to a server.
-------------- Original message -------------- 

> 
> Hi Bob, 
> 
> You need to bring the file across as binary and then do a field by field 
> conversion using the String and 
> com.ibm.as400.access.AS400PackedDecimal classes. 
> 
> If you bring it down as text, each byte, typically, is converted to 
> ASCII. That doesn't work for true numeric fields because they aren't 
> characters but binary values that don't map to a character set. The same is 
> true for a non-EBCDIC file that contains numbers and characters, and is why 
> trying to just use an encoding translation on that kind of file doesn't 
> work. 
> 
> As Mark indicated, BinaryConverter doesn't understand that C, D and/or F 
> are sign indicators and takes them at their hex value. While we are 
> accustomed to 'F' for positive values on the '400, 'C' is an explicit 
> positive used often on mainframes. If my recollection is correct, any value 
> other than 'D' is taken as positive. 
> 
> Have fun, 
> 
> 
> 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 
> 
> 
> ----- Original Message ----- 
> From: "Bob Szemethy" 
> To: 
> Sent: Monday, August 23, 2004 10:51 PM 
> Subject: Help w/ Packed Decimal 
> 
> 
> > Hi all - 
> > 
> > A quick question about a flat file built on a S/390, that I am trying to 
> > process on a Windows box using JTOpen. 
> > 
> > I have access to the file only though an FTP applet that our HQ 
> > maintains, and I pulled the file down as text and as binary. When I'm 
> > processing the file, I have no trouble with the text fields, but there 
> > are some packed decimal fields that are not coming across. 
> > 
> > I also was able to parse the binary file when I set the encoding to 
> > "IBM1047", but had the same problem with the packed fileds. 
> > 
> > I tried the BinaryConverter class, and the method to convert to Hex 
> > string for the byte array, and for the text and binary files, it returns 
> > the following sting for a 4 byte number : "0000000C", which I understand 
> > to be 12, but I know the number should be 1. 
> > 
> > So my question is this: Can I parse a packed-decimal field in a file 
> > that has been translated to ASCII or Unicode? Thanks for any help. 
> > 
> > Bob 
> > 
> 
> 
> 
> 
> 
> 
> -- 
> This is the Java Programming on and around the iSeries / AS400 (JAVA400-L) 
> mailing list 
> To post a message email: JAVA400-L@xxxxxxxxxxxx 
> To subscribe, unsubscribe, or change list options, 
> visit: http://lists.midrange.com/mailman/listinfo/java400-l 
> or email: JAVA400-L-request@xxxxxxxxxxxx 
> Before posting, please take a moment to review the archives 
> at http://archive.midrange.com/java400-l. 
> 

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.