Search code examples
ibm-midrangerpgle

Rpgle data struct prob


The chars are I am putting in are as follows:-
"췡전V" which are UTF16 hex as CDE1C8040056

Some one please help me understand what is going on:-
1) I change my job CCSID to 833


2) Code I run is as follows:-

D w_VIN           ds                              
D  vin1                               like(AAF010)
D  vin2                               like(AACDE1)
D  vin3                               like(AAF006)

where:- AAF010 is a C(10) CCSID(1200), AACDE1 is a C(1) CCSID(1200) and AAF006 is C(6)

where DataFld C(17) CCSID(1200) The code that is executed is :-

w_VIN  = dataFld;


EVAL datafld:x

00000     CDE1C804 00560020 00200020 00200020
00010     00200020 00200020 00200020 00200020
00020     0020.... ........ ........ ........

EVAL w_VIN:x

00000     0EC2D7B8 E50FE540 40404040 40404040
00010     40404040 40404040 40404040 40404040
00020     4040.... ........ ........ ........

I am expecting CDE1C8040056, I really don't understand why, someone please explain? How do I get the result I want?
Regards,
Jemrug


Solution

  • Data structures do not have a data type explicitly assigned to them. They are always implicitly fixed char fields using the Job CCSID. So w_VIN is CHAR() CCSID(833). Nothing you can do about that. However, the sub-fields can be anything you want, and you can overlay fields on each other to slice and dice the data structure however you want. For example:

    dcl-ds w_VIN;
      vin1          Like(aaf010);
      vin2          Like(aacde1);
      vin3          Like(aaf006);
      ucs2_VIN      Like(dataFld) Pos(1);
    end-ds;
    

    Now w_VIN is not defined like dataFld so a conversion would occur if you did

    w_VIN = dataFld;
    

    ucs2_VIN is defined exactly like dataFld, and no conversion would occur if you did

    ucs2_VIN = dataFld;
    

    Since ucs2_VIN explicitly starts at the first character of the data structure, it will overlay vin1, vin2, and vin3. The sequence of defining these sub-fields matters. If you put ucs_VIN first, vin1, vin2, and vin3 would follow it in the structure, but since I defined the data structure first, and then added an additional definition at the end, that last definition will be overlaid on top of the other definitions.