%CHECK (文字の検査)

%CHECK(comparator : base {: start})

%CHECK は、ストリング・コンパレーター の中に現れない文字を含む ストリング 基底 の、最初の位置を戻します。基底 のすべての文字が コンパレーター にも現れていれば、関数は 0 を戻します。

検査は開始位置から始められ、コンパレーター・ストリングに含まれていない文字が見付かるまで、右方へと続けられます。 開始位置のデフォルトの値は 1 です。

1 番目のパラメーターのタイプは、文字、図形、UCS-2、固定または可変長でなければなりません。2 番目 のパラメーターは、1 番目のパラメーターと同じタイプである必要があります。 3 番目のパラメーターが指定されている場合、それは、小数点以下の桁数がゼロである非浮動数値でなければなりません。

詳細については、ストリング命令または 組み込み関数を参照してください。

図 1. %CHECK の例
 *..1....+....2....+....3....+....4....+....5....+....6....+....7...+....
 *--------------------------------------------------
 * A string contains a series of numbers separated
 * by blanks and/or commas.
 * Use %CHECK to extract the numbers
 *--------------------------------------------------
D string          s             50a   varying
D                                     inz('12, 233 17, 1, 234')
D delimiters      C                   ' ,'
D digits          C                   '0123456789'
D num             S             50a   varying
D pos             S             10i 0
D len             S             10i 0
D token           s             50a   varying

 /free

     // make sure the string ends with a delimiter
     string = string + delimiters;

     dou string = '';

       // Find the beginning of the group of digits
       pos = %check (delimiters : string);
       if (pos = 0);
          leave;
       endif;

       // skip past the delimiters
       string = %subst(string : pos);

       // Find the length of the group of digits
       len = %check (digits : string) - 1;

       // Extract the group of digits
       token = %subst(string : 1 : len);
       dsply ' ' ' ' token;

       // Skip past the digits
       if (len < %len(string));
         string = %subst (string : len + 1);
       endif;

     enddo;

 /end-free

図 2も参照してください。