ヌル文字で終了するストリングの入手に使用する %STR
この関数は、式の右側で使用された場合、指定された長さの中の 最初のヌル文字 (x'00) までで (ただし、その文字は含まない)、最初の パラメーターによって指し示されたデータを戻します。 この組み込み関数は、文字式が有効であればどこでも使用する ことができます。 ヌル文字終了記号が指定された長さの中で見付からない場合、 実行時にエラーとはなりません。この場合、結果の値の長さは指定された長さと同じになります。
図 1. %STR (右側) 例 1
*..1....+....2....+....3....+....4....+....5....+....6....+....7...+....
D String1 S *
D Fld1 S 10A
/FREE
Fld1 = '<' + %str(String1) + '>';
// Assuming that String1 points to '123¬' where '¬' represents the
// null character, after the EVAL, Fld1 = '<123> '.
/END-FREE
次は、2 番目のパラメーターを指定した %STR の例です。
図 2. %STR (右側) 例 2
*..1....+....2....+....3....+....4....+....5....+....6....+....7...+....
D String1 S *
D Fld1 S 10A
/FREE
Fld1 = '<' + %str(String1 : 2) + '>';
// Assuming that String1 points to '123¬' where '¬' represents the
// null character, after the EVAL, Fld1 = '<12> '.
// Since the maximum length read by the operation was 2, the '3' and
// the '¬' were not considered.
/END-FREE
この例で、ヌル文字終了記号は、指定された最大長の中で見付かります。
図 3. %STR (右側) 例 3
*..1....+....2....+....3....+....4....+....5....+....6....+....7...+....
D String1 S *
D Fld1 S 10A
/FREE
Fld1 = '<' + %str(String1 : 5) + '>';
// Assuming that String1 points to '123¬' where '¬' represents the
// null character, after the EVAL, Fld1 = '<123> '.
// Since the maximum length read by the operation was 5, the
// null-terminator in position 4 was found so all the data up to
// the null-terminator was used.
/END-FREE