Hi David,

Sorry, I got called into a client emergency.

First, I know that a char is unsigned, just been working with ASCII too much lately. In my original mail, convert 127 to 255 and 128 to 256. Figured someone would ping me for that.

I may still be on the wrong track, but I think what I woud try in the situation you describe, is in-memory conversion of the Unicode string to a string with the destination character set, then write a substring of max column length ( or space/blank nearest to the max length ) to the database. That way maybe the shift won't get lost and you don't have to truck through characters. No guarantees, since I haven't actually tried it and don't have time to play at the moment.


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: "David Gibbs" <david@xxxxxxxxxxxx>
To: "Java Programming on and around the iSeries / AS400" <java400-l@xxxxxxxxxxxx>
Sent: Tuesday, June 24, 2008 4:05 PM
Subject: Re: Determine if a String will result in a double byte valuein DB2/400?


Joe Sam Shirah wrote:
You should be able to take the Unicode string character by character
and put it into a char variable, which is 16 bits. Check the numeric
value of the char. If GT 127, then it's a double byte.

Yeah, this I know.

I think my question is kind of imprecise.

What I'm trying to calculate is: How much of a Unicode string can I fit
in a double byte field.

For example ... if I have a Unicode string that contains a mix of
Japanese and English, alternating back and forth in parts ... is there a
way I can determine how much of that string I can fit in a fixed length
double byte database field. Since the double byte version of the value
will contain one or more sets of shift out/shift in characters, the
effective length gets reduced

I also wonder how helpful persisting only half a string will be.

This is transitory summary data ... strictly for human consumption. It
will be displayed in 5250 subfile. If the value is too long, it's
accepted that the data will be truncated.

You do know that the AS/400 now supports UTF-8, right? Of course,
that may not be an option; don't know your app. HTH,

Sadly it's not an option ... that would have solved a boat load of
problems from the getgo.

I also think that, unless you've got things set up really funny, you
should not get an "sql statement overflowing the field." I'd expect a data
truncation warning, which you can program to ignore, sort of getting
automatic trimming.

The odd thing about that is ... if I try to put 120 unicode bytes into a
120 byte double byte field, the trailing shift in is lost. At least it
was when I last tried this (more than a year ago).

david

--
IBM System i - For when you can't afford to be out of business

--
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.



This thread ...

Follow-Ups:
Replies:

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

This mailing list archive is Copyright 1997-2020 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].