自由形式構文 | (許可されていない - %SUBST を使用) |
コード | 演算項目 1 | 演算項目 2 | 結果フィールド | 標識 | ||
---|---|---|---|---|---|---|
SUBST (E P) | 取り出す長さ | 基本ストリング:開始 | ターゲット・ストリング | _ | ER | _ |
SUBST 命令は、演算項目 2 に指定された位置から始まる演算項目 1 に指定 された長さのサブストリングを演算項目 2 から戻して、このサブストリングを 結果フィールドに入れます。 演算項目 1 が指定されていない場合には、開始位置からのストリングの長さが 使用されます。 図形ストリングまたは UCS-2 ストリングの場合には、開始位置は 2 バイト単位で計算されます。 基本ストリングとターゲット・ストリングは両方とも同じタイプ (両方とも文字、両方とも図形、または両方とも UCS-2) でなければなりません。
演算項目 1 には、演算項目 2 に指定されたストリングから抜き出すストリングの 長さの値を入れることができます。これは小数点以下の桁数がゼロの数値でなければ ならず、フィールド名、配列要素、テーブル名、リテラル、または名前のついた 定数のいずれかを入れることができます。
演算項目 2 には、基本ストリングか、または基本ストリングに ':' を付け開始位置を指定したものを入れなければなりません。 基本ストリング部分には、フィールド名、配列要素、名前のついた定数、 データ構造名、テーブル名、またはリテラルのいずれかを入れることができま す。 開始位置は小数点以下の桁数がゼロの数値でなければならず、フィールド名、 配列要素、テーブル名、リテラル、または名前のついた定数のいずれかを 入れることができます。 開始位置が指定されていない場合には、SUBST は基本ストリングの 1 桁目から 開始します。 図形ストリングまたは UCS-2 ストリングの場合には、開始位置は 2 バイト単位で計算されます。
抜き出されるサブストリングの開始位置および長さは、正の整数でなければ なりません。 開始位置は基本ストリングの長さを超えてはならず、長さは開始位置からの基 本ストリングの長さを超えてはなりません。 これらの条件のいずれかまたは両方が 満たされない場合には、この命令は実行されません。
SUBST 例外 (プログラム状況コード 100) を 処理するために、命令コード拡張 'E' またはエラー標識 ER を指定できますが、 両方を指定することはできません。 エラー処理の詳細について は、プログラム例外/エラーを参照してください。
結果フィールドは文字、図形、または UCS-2 でなければならず、フィールド名、配列要素、データ構造、またはテーブル名のいずれかを入れることができます。 結果は左寄せされます。 結果フィールドの長さは、少なくとも演算項目 1 に指定された長さと同じでな ければなりません。サブストリングが結果フィールドに指定されたフィールドより 長い場合には、そのサブストリングの右側で切り捨てが行われます。 結果のフィールドが可変長の場合、その長さは変わりません。
詳細については、ストリング命令を参照してください。
*...1....+....2....+....3....+....4....+....5....+....6....+....7...+.... CL0N01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq.... * * The SUBST operation extracts the substring from factor 2 starting * at position 3 for a length of 2. The value 'CD' is placed in the * result field TARGET. Indicator 90 is not set on because no error * occurred. C C Z-ADD 3 T 2 0 C MOVEL 'ABCDEF' String 10 C 2 SUBST String:T Target 90 * * In this SUBST operation, the length is greater than the length * of the string minus the start position plus 1. As a result, * indicator 90 is set on and the result field is not changed. C C MOVE 'ABCDEF' String 6 C Z-ADD 4 T 1 0 C 5 SUBST String:T Result 90 C * In this SUBST operation, 3 characters are substringed starting * at the fifth position of the base string. Because P is not * specified, only the first 3 characters of TARGET are * changed. TARGET contains '123XXXXX'. C C Z-ADD 3 Length 2 0 C Z-ADD 5 T 2 0 C MOVE 'TEST123' String 8 C MOVE *ALL'X' Target C Length SUBST String:T Target 8
* * This example is the same as the previous one except P * specified, and the result is padded with blanks. * TARGET equals '123 '. C C Z-ADD 3 Length 2 0 C Z-ADD5 T 2 0 C MOVE 'TEST123' String 8 C MOVE *ALL'X' Target C Length SUBST(P) String:T Target 8 C C * * In the following example, CITY contains the string * 'Toronto, Ontario'. The SCAN operation is used to locate the * separating blank, position 9 in this illustration. SUBST * without factor 1 places the string starting at position 10 and * continuing for the length of the string in field TCNTRE. * TCNTRE contains 'Ontario'. C ' ' SCAN City C C ADD 1 C C SUBST City:C TCntre * * Before the operations STRING=' John & * RESULT is a 10 character field which contains 'ABCDEFGHIJ'. * The CHECK operation locates the first nonblank character * and sets on indicator 10 if such a character exists. If *IN10 * is on, the SUBST operation substrings STRING starting from the * first non-blank to the end of STRING. Padding is used to ensure * that nothing is left from the previous contents of the result * field. If STRING contains the value ' HELLO ' then RESULT * will contain the value 'HELLO ' after the SUBST(P) operation. * After the operations RESULT='John '. C C ' ' CHECK STRING ST 10 C 10 SUBST(P) STRING:ST RESULT
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.