%UCS2 (Convert to UCS-2 Value)
%UCS2 converts the value of the expression from character, graphic, or UCS-2 and returns a UCS-2 value. The result is varying length if the parameter is varying length, or if the parameter is single-byte character.
The second parameter, ccsid, is optional and indicates the CCSID of the resulting expression. The CCSID defaults to the default UCS-2 CCSID of the module as specified by control keyword CCSID(*UCS2).
If the parameter is a constant, the conversion will be done at compile time.
If the conversion results in substitution characters, a warning message is issued at compile time. At run time, status 00050 is set and no error message is issued.
For more information, see Conversion Operations or Built-in Functions.
HKeywords++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
H CCSID(*UCS2 : 13488)
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++
D char S 5A INZ('abcde')
D graph S 2G INZ(G'oAABBi')
* The %UCS2 built-in function is used to initialize a UCS-2 field.
D ufield S 10C INZ(%UCS2('abcdefghij'))
D ufield2 S 1C CCSID(61952) INZ(*LOVAL)
D isLess 1N
D proc PR
D uparm 2C CCSID(13488) CONST
CL0N01Factor1+++++++Opcode&ExtExtended-factor2+++++++++++++++++++++++++
C EVAL ufield = %UCS2(char) + %UCS2(graph)
* ufield now has 7 UCS-2 characters representing
* 'a.b.c.d.e.AABB' where 'x.' represents the UCS-2 form of 'x'
C EVAL isLess = ufield < %UCS2(ufield2:13488)
* The result of the %UCS2 built-in function is the value of
* ufield2, converted from CCSID 61952 to CCSID 13488
* for the comparison.
C EVAL ufield = ufield2
* The value of ufield2 is converted from CCSID 61952 to
* CCSID 13488 and stored in ufield.
* This conversion is handled implicitly by the compiler.
C CALLP proc(ufield2)
* The value of ufield2 is converted to CCSID 13488
* implicitly, as part of passing the parameter by constant reference.
Note: The graphic literal in this example is
not a valid graphic literal. See Graphic Format for more information.