%CHAR(expression{:format})
%CHAR は式の値を図形、UCS-2、数値、日付、時刻、またはタイム・スタンプの各データから文字タイプに変換します。変換後の値は変更されないままですが、文字データとの互換性が ある形式で戻されます。
パラメーターが定数の場合、変換はコンパイル時に行われます。
UCS-2 変換の結果、置換文字になると、パラメーターが定数の 場合にはコンパイラー・リスト内で警告メッセージが出されます。 定数でない場合には、実行時に状況 00050 が設定されます が、エラー・メッセージは出されません。
図形データの場合、戻り値にはシフトインおよびシフトアウト文字が含まれます。 たとえば、5 文字の図形フィールドが変換される場合、戻り値は 12 文字 (10 バイトの図形データと 2 つのシフト文字) になります。式の値が可変長である場合、戻り値は 可変長形式になります。
日付、時刻、またはタイム・スタンプのデータの場合、2 番目のパラメーターには、戻された文字データが変換される目標の日付、時刻、またはタイム・スタンプの形式が入ります。 戻り値には、指定された形式の後にゼロが続いていない限り、区切り記号を含みます。
数値データの場合、式の値が浮動であれば、結果は浮動形式になります (たとえば、「+1.125000000000000E+020」)。 そうでない場合の結果は、値が負であれば先行負符号がついた 10 進数形式になります。 先行ゼロはありません。小数点として使用される文字は、制御仕様書の DECEDIT キーワードで指定されている文字になります (デフォルトは「.」)。たとえば、パック (7,3) の %CHAR 式は、値 「-1.234」を戻すことになります。
詳細については、変換命令または 組み込み関数を参照してください。
*..1....+....2....+....3....+....4....+....5....+....6....+....7...+.... D Name S 20G VARYING INZ(G'oXXYYZZi') D date S D INZ(D'1997/02/03') D time S T INZ(T'12:23:34') D result S 100A VARYING D points S 10i 0 INZ(234) *----------------------------------------------------------------- * To format the time and date with the default formats, use this: *----------------------------------------------------------------- /FREE result = 'It is ' + %CHAR(time) + ' on ' + %CHAR(date); // If the default formats are both *USA, // result = 'It is 12:23 PM on 02/03/1997' //------------------------------------------------------------- // To format the time and date with the job formats, use this: //------------------------------------------------------------- result = 'It is ' + %CHAR(time : *jobrun) + ' on ' + %CHAR(date : *jobrun); // If the job date format is *MDY- and the time separator is '.', // then the result = 'It is 12.23.34 on 97-02-03' //-------------------------------------------------------------- // To format the time and date with specific formats, use this: //-------------------------------------------------------------- result = 'It is ' + %CHAR(time : *hms:) + ' on ' + %CHAR(date : *iso); // result = 'It is 12:23:34 on 1997-02-03' // //------------------------------------------------------------- // You can use %subst with the %char result if you only want // part of the result //------------------------------------------------------------- result = 'The time is now ' + %SUBST (%CHAR(time):1:5) + '.'; // result = 'The time is now 12:23.' //------------------------------------------------------------- // Use %CHAR to convert a graphic value to character so it // can be concatenated with a character value. //------------------------------------------------------------- result = 'The customer''s name is ' + %CHAR(Name) + '.'; // result = 'The customer's name is oXXYYZZi.' //---------------------------------------------------- // Use %CHAR to convert a number to character format: //---------------------------------------------------- result = 'You have ' + %char(points) + ' points.'; // result = 'You have 234 points.' // /END-FREE