Skip to main content

This documentation is for an older version of this product. See the latest version of this content.Opens in a new tab

入れ子の $Order ループ

入れ子になった $Order ループ (ツリーの枝内の各レベルに 1 つ) を使用すると、ID 番号を示す葉ノードに到達できます。その後 ID 番号を使用してデータ・グローバルに戻り、必要な情報を取得します。例として、名前インデックスを使用します。ここでは、各姓データに対応する名前すべてを検索するために、新規のループを呼んでいます。また、そのフルネームに対し、新規ループで該当するすべての ID 番号を検索します。ID を使用して、^PersonD の残りのデータを取得します。

VS Code - ObjectScript


/// examples for ObjectScript Tutorial
Class ObjectScript.Examples
{

/// Loop through the name index and display the records
ClassMethod NameLoop()
{
    // loop through last names
    set ln = ""
    for {
        set ln = $order(^PersonI("Name", ln))
        quit:(ln = "")
        // for each last name, loop through first names
        set fn = ""
        for {
            set fn = $order(^PersonI("Name", ln, fn))
            quit:(fn = "")
            // for each last name and first name, loop through id numbers
            set id = ""
            for {
                set id = $order(^PersonI("Name", ln, fn, id))
                quit:(id = "")
                // once you have an id number, get the data and display it
                set rec = ^PersonD(id)
                write !, $list(rec, 1),
                      ?15, $list(rec, 2),
                      ?30, $zdate($list(rec, 3), 2)
            }
        }
    }
}
}
ターミナルを使用したテスト


USER>do ##class(ObjectScript.Examples).NameLoop()

Agee,Tommie    617-333-3333   09 Aug 42
Jones,Bobby    333-444-5555   10 Feb 70
Jones,Cleon    111-111-1111   04 Aug 42
Swoboda,Ron    222-222-2222   08 Jun 44
USER>
FeedbackOpens in a new tab