NewBie's Corner Session 27 Traversing A Global with $Order Part 1
Welcome to NewBie's Corner, a weekly or biweekly post covering basic Caché Material.
Traversing A Global
Perhaps the most difficult concept in Caché/MUMPS is its Global Structure. This session and several that follow it deals with the Global Structure. However, just presenting the material will not guarantee your understanding of it. You must experiment with the data and concepts that are presented.
In this session, we are going to create a small Global of three levels deep, and then show the code to Traverse the Global.
The following code sets up the ^Trans Global and then gives the code to traverse it. I suggest you study the code, experiment with it until you have a good feel for how the Global is structured and how to traverse it.
Set ^Trans("Cars","Chevy","Malibu")="4 Speed"
Set ^Trans("Cars","Toyota","Tercel")="Not as Nice"
Set Sub1="" For Do Q:Sub1=""
. Set Sub1=$O(^Trans(Sub1)) Q:Sub1=""
. Write !,Sub1
. Set Sub2="" For Do Q:Sub2=""
. . Set Sub2=$O(^Trans(Sub1,Sub2)) Q:Sub2=""
. . Write !," ==>",Sub2
. . Set Sub3="" For Do Q:Sub3=""
. . . Set Sub3=$O(^Trans(Sub1,Sub2,Sub3)) Q:Sub3=""
. . . Write !," ====>",Sub3
. . . Set Data=(^Trans(Sub1,Sub2,Sub3))
. . . Write !," ======>",Data
Please note that there are two spaces after the "For" and after the "Do".
In traversing the Global the $Order ($O) command is used, more on the $Order command in subsequent sessions. I suggest you do some reading on the $Order command, see the documentation at: http://localhost:57772/csp/docbook/DocBook.UI.Page.cls?KEY=RCOS_forder#RCOS_B70911
This is not the only method of traversing a Global. I will show different methods of traversing the Global in upcoming sessions.
If you have a comment, please respond through the InterSystems Developer Community, don't send me private email, unless of course you wish to address me only.
See "Newbie's Corner Index" for an index of all NewBies' Posts