Skip to main content

This is documentation for Caché & Ensemble.

For information on converting to InterSystems IRISOpens in a new window, see the InterSystems IRIS Migration Guide and Migrating to InterSystems IRIS, both available on the WRC Distributions pageOpens in a new window (login required).

Starting Focused $Order Loops

Let's focus the start of the loop. Assume the variable sub holds the substring, and that the substring is not empty. Instead of setting ln to "", as we did in the previous example, we want to start the $Order loop based on the substring. But we can't simply set ln equal to the substring. What if sub equals a last name that's already in the database? Then the loop will start with the next name, even though there's an exact match for sub in the index, because of the initial $Order.

To deal with this, use $Order once in reverse, to set ln equal to the last name preceding sub. Then the loop can proceed and generate the names that follow. But we still need to focus the end of the loop so that we don't get “Swoboda”.

SAMPLES>do ^loopstart
Search for: J
Copy code to clipboard

The loopstart.mac code:

loopstart ; loop through last names
    read "Search for: ",sub
    set ln = $order( ^PersonI("Name", sub), -1)
    for {
        set ln = $order( ^PersonI("Name", ln) )
        quit:(ln = "")
        write !, ln
Copy code to clipboard
FeedbackOpens in a new window