自由形式構文 | (許可されていない - %LOOKUP 組み込み関数または %TLOOKUP 組み込み関数を使用) |
コード | 演算項目 1 | 演算項目 2 | 結果フィールド | 標識 | ||
---|---|---|---|---|---|---|
LOOKUP | ||||||
(配列) | 検索引数 | 配列名 | HI | LO | EQ | |
(テーブル) | 検索引数 | テーブル名 | テーブル名 | HI | LO | EQ |
LOOKUP 命令では、配列またはテーブルの特定の要素の検索を行うことが できます。 演算項目 1 は検索引数 (指定された配列またはテーブル内で一致す るものを見付けたいデータ) です。 演算項目 1 は、リテラル、フィールド名、配列要素、テーブル名、名前のつい た定数、または形象定数とすることができます。 比較の性質はデータ・タイプによって異なります。
演算項目 1 にテーブルが指定されている場合には、使用される検索引数は LOOKUP 命令で最後に選択されたテーブルの要素か、または前の LOOKUP が処理 されていなければテーブルの最初の要素になります。 検索する配列またはテーブルは演算項目 2 に指定します。
テーブルの LOOKUP の場合には、結果フィールドに 2 番目のテーブルの名前 を入れて、そこから要素 (最初のテーブルの要素と対応する位置にある) を検 索することができます。 検索したい要素を参照するために 2 番目のテーブルの 名前を使用することができます。 演算項目 2 に配列名が入っている場合には、 結果フィールドはブランクでなければなりません。
結果の標識は LOOKUP の検索条件を指定します。 この標識は、最初に、実行される検索 を判別し、次にその検索の結果を反映するために、 71 から 76 桁目に指定しなければなりません。 指定された標識がオンに設定されるのは、検索が正常に実行された場合だけです。 使用できる標識の数は 2 つ以下です。 結果の標識は、等 (EQ) と高 (HI) または等 (EQ) と低 (LO) に割り当てることができます。 プログラムは、指定された優先順位が等しいどちらかの 条件を満たす項目を検索します (すなわち、等しい項目が見付からない場合には、 低い方または高い方で一番近い項目が選択されます)。
75 から 76 桁目に標識を指定した場合、%EQUAL 組み込み関数は、検索引数に正確に一致 する要素が見付かった場合に '1' を戻します。%FOUND 組み込み関数は、指定された検索が成功した場合に '1' を 戻します。
結果の標識は、等と低または等と高に割り当ていることができます。同じ LOOKUP 命令で高と低を指定することはできません。 コンパイラーは、LOOKUP 命令に高または低の標識が指定されている場合には、 配列またはテーブルが分類され、順序付けられていると見なします。 LOOKUP 命令は、指定された優先順位が等しいか低い/等しいか大きい/等 条件を満たす項目を検索します。
LOOKUP 命令を使用する場合には、次のことに留意してください。
詳細については、配列命令を参照してください。
*...1....+....2....+....3....+....4....+....5....+....6....+....7....+.... CL0N01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq.... * * In this example, the programmer wants to know which element in * ARY the LOOKUP operation locates. The Z-ADD operation sets the * field X to 1. The LOOKUP starts at the element ARY that is * indicated by field X and continues running until it finds the * first element equal to SRCHWD. The index value, X, is set to * the position number of the element located. C C Z-ADD 1 X 3 0 C SRCHWD LOOKUP ARY(X) 26 C * In this example, the programmer wants to know if an element * is found that is equal to SRCHWD. LOOKUP searches ARY until it * finds the first element equal to SRCHWD. When this occurs, * indicator 26 is set on and %EQUAL is set to return '1'. C C SRCHWD LOOKUP ARY 26 C * The LOOKUP starts at a variable index number specified by * field X. Field X does not have to be set to 1 before the * LOOKUP operation. When LOOKUP locates the first element in * ARY equal to SRCHWD, indicator 26 is set on and %EQUAL is set * to return '1'. The index value, X, is set to the position * number of the element located. * C C SRCHWD LOOKUP ARY(X) 26
* In this example, an array of customer information actually consists * of several subarrays. You can search either the main array or the * subarrays overlaying the main array. D custInfo DS D cust DIM(100) D name 30A OVERLAY(cust : *NEXT) D id_number 10I 0 OVERLAY(cust : *NEXT) D amount 15P 3 OVERLAY(cust : *NEXT) * You can search for a particular set of customer information * by doing a search on the "cust" array C custData LOOKUP cust(i) 10 * You can search on a particular field of the customer information * by doing a search on one of the overlay arrays C custName LOOKUP name(i) 11 * After the search, the array index can be used with any of the * overlaying arrays. If the search on name(i) is successful, * the id_number and amount for that customer are available * in id_number(i) and amount(i).
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.