%UCS2 (UCS-2 値への変換)

%UCS2 は、文字、図形、または UCS-2 から式の値を変換し、UCS-2 値を 戻します。結果は、パラメーターが可変長である場合か、パラメーター が 1 バイト文字である場合は、可変長になります。

2 番目のパラメーターの ccsid はオプション で、結果の式の CCSID を示します。CCSID のデフォルト値は 13488 です。

パラメーターが定数の場合、変換はコンパイル時に行われます。

変換の結果、置換文字になる場合、コンパイル時に警告メッセージ が出されます。 実行時には状況 00050 が設定され、エラー・メッセージは出されません。

詳細については、変換命令または 組み込み関数を参照してください。

図 242. %UCS2 の例
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                       2G   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.
注:
この例の GRAPHIC リテラルは、無効な GRAPHIC リテラルです。 詳しくは、グラフィック形式を参照してください。