Search code examples
ibm-midrangerpgle

Rpgle Double byte issue


Have an issue with the following bit of code:-

C                   eval      aaCHNO=%ucs2('0000000000')        
C**                 move      w_Chano       aaCHNO              
C                   Evalr     aaCHNO= %ucs2(%editc(w_Chano:'X'))

Definitions :

AACHNO            Char(10) CCSID(1200)  
W_CHANO           Packed(6,0)  

In AACHNO was expecting :- 0000123456 but get 'bbbb123456' where b=blank why?

How do I get the results I want? cheers, Jemrug


Solution

  • The op-code EVALR does not work like MOVE, it works like MOVE(P). In order to get the behavior you want, you are going to have to use %SUBST() or concatenate '0's to the front of your value like this:

    C                   Evalr     aaCHNO = %ucs2('0000000000') + %ucs2(%editc(w_Chano:'X'))
    

    or in free format use:

    evalr aaCHNO = %ucs2('0000000000') + %ucs2(%editc(w_Chano:'X'));
    

    Note: There are a couple constructs that you do not actually attach a type to, so they are defined as char(). Character constants are one of them. Another is data structures. When you are using UCS2 data, you must remember this and convert the constants, and only use fields or sub-fields explicitly defined as UCS2. Otherwise conversion will take place.