+ Reply to Thread
Results 1 to 4 of 4

Thread: Substring of double byte characters

  1. #1
    Guest.Visitor Guest

    Default Substring of double byte characters

    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.

  2. #2
    Guest.Visitor Guest

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

  3. #3
    Guest.Visitor Guest

    Default 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

  4. #4

    Default

    Anybody has a sample interactive program that handles mix alphanumeric and DBCS-open type fields in a file?
    Ineed to be able to maintain a field that can contain both english and chinese characters.
    Thankyou in advance.

+ Reply to Thread

Similar Threads

  1. Transferring double byte data from Unix to AS400
    By as400info in forum IBM i (OS/400, i5/OS)
    Replies: 1
    Last Post: 07-22-2003, 01:58 AM
  2. Replies: 0
    Last Post: 07-21-2003, 10:55 PM
  3. Replies: 0
    Last Post: 06-18-2001, 08:51 AM
  4. Double Byte Questions
    By Guest.Visitor in forum Application Software
    Replies: 2
    Last Post: 01-26-2000, 07:09 AM
  5. Cawin & double byte
    By Guest.Visitor in forum Programming
    Replies: 2
    Last Post: 11-24-1999, 10:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts