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 Traverse Loops

Let's focus the start of the loop. Assume the variable substr 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 Traverse() loop based on the substring. But we can't simply set ln equal to the substring. What if substr 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 substr in the index, because of the initial Traverse().

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

substr = "J"
ln = traverse(^PersonI("Name", substr), -1)
do
    ln = traverse(^PersonI("Name", ln) )
    if ln = "" then exit do
    println ln
loop
Copy code to clipboard

The example code is in the loopstart subroutine of BAStraverse.BAS. Run it—passing the substr—using the Terminal.


SAMPLES>do loopstart^BAStraverse("J")
SAMPLES>do loopstart^BAStraverse("Jones")
Copy code to clipboard
FeedbackOpens in a new window