Skip to main content

This is documentation for Caché & Ensemble. See the InterSystems IRIS version of this content.Opens in a new tab

For information on migrating to InterSystems IRISOpens in a new tab, see Why Migrate to InterSystems IRIS?

$Order 関数 (2)

$Order では、逆の順序で添え字を検索することもできます。この場合、第 2 引数で -1 を指定します。

SAMPLES>write

x(1)=1
x(4)=2
x(9)=3
SAMPLES>write $order( x(""), -1 )
9
SAMPLES>write $order( x(9), -1 )
4
SAMPLES>write $order( x(4), -1 )
1
SAMPLES>write $order( x(1), -1 )

SAMPLES>

多くの場合、$Order を使用して有効な添え字値を取得する際には、配列のその位置に格納されている値も取得します。

例えば、次の添え字を取得し (a)、値をそこに格納します (b)。

SAMPLES>set a = $order( x(4) ), b = x(a) write a, "   ", b 
9   3

同じことを簡単で高速な方法で実行できます。$Order の 3 番目の引数に変数名を割り当てると、2 ステップの代わりに 1 ステップでこれらの値を取得できます。2 番目の引数には 1 (前方検索) または -1 (後方検索) を指定します。

SAMPLES>set a = $order( x(4), 1, b) write a, "   ", b
9   3

FeedbackOpens in a new tab