I had created a physical file called 'Customer', one of the field in this file, that is 'customername' is a double byte field which can contains chinese characters. My problem is when I use %Substring to extract partially (eg first 2 characters) from this field (based on how many characters user was entered) and compare with the user key in field. The extracted field was not equal with the user key in field (In fact, both should be equal). I found that, If I %substring all the characters from this customername field, I do not have this problem. Can anybody give me some advise, what other method I can use to avoid problem. My intention is to find out how many records match the name key in by the user. For example, if user enter John, I want to know how many records are John%, that is JohnLee, JohnAlan etc. Thank you in advance.
Unconfigured Ad Widget
Collapse
Substring of double byte characters
Collapse
X
-
Substring of double byte characters
According to the RPG Reference manual the length of a UCS-2 (double-byte) field, in bytes, is two times the number of UCS-2 characters in the field. Is it possible that you need to use a length equal to two times the number of characters you want to extract? For example, if you want to extract the first two characters you would use a length of 4. Also, did you know you can convert a character expression to UCS-2 with the %UCS2 built-in RPG function.
-
-
Substring of double byte characters
Hi kk, The RPG operators are smart enough to pull one or two bytes for a character, depending on the definition/format. What I expect is that when you are performing the substring, you are receiving it into a single byte character OR comparing to a single byte character. Here's what the 4.4 manual has to say about these comparisons: "If character, graphic, or UCS-2 fields are compared, fields of unequal length are aligned to their leftmost character. The shorter field is filled with blanks to equal the length of the longer field so that the field lengths are equal for comparison." So, if we let 'b' = blank ( hex 40 ), then let's say we have 'J' as the character data: Single byte: 'J' ( 0xD1 ) Double byte: 'b' 'J' ( 0x40D1 ) When comparing these two, from the above rule, we'd get: Single byte converted to: 'J' 'b' ( 0xD140 ) which doesn't match. You need to define your result/comparison field as Graphic or UCS-2 ( known to the rest of the world as unicode ) or move it properly to such a field for a valid comparison. I assume it works with the entire field because your types match then; check the code and definitions. Check your compilation print to see how RPG defines the field in the file. UCS-2 type is new for V4.4, so you may see it as Graphic. Graphic is defined as two EBCDIC bytes, I assume UCS-2 matches standard unicode. From your point of view they should be equivalent. Best, Joe Sam Joe Sam Shirah Autumn Software Consulting/Development/Outsourcing Please Note New Email: jshirah@attglobal.net Visit our User Group at: http://www.jax400.com
Comment
-
Comment