Database Wildcards

Primary tabs

Greetings,

How do I organize a wildcard search with respect to a database search?

Example of what I am trying to do:  s x=$o(^G("ABC","A*",x))

Trying to navigate through the ^G global for all occurrences of "ABC", and "A*" ("A"+wildcard) but I am new to M and don't know positively how to do this.  Perhaps I don't use an "*" at all, rather; another convention altogether.

Please advise.

Thanks in advance for everyone's assistance.

  • 0
  • 0
  • 295
  • 0
  • 2

Answers

Hi Russel,

I would solve the problem along the following lines...

set k2=$s($d(^G("ABC","A")):"A",1:$o(^G("ABC","A")))
while $e(k2,1)="A" {
   set k3=$o(^G("ABC",k2,""))
   while k3'="" {
     write !,k2," ",k3
     set k3=$o(^G("ABC",k2,k3))
   }
   set k2=$o(^G("ABC",k2))
}

Explanation...

//set k2 to either "A" if that key exists in the data, or the next key following "A".
set k2=$s($d(^G("ABC","A")):"A",1:$o(^G("ABC","A")))

//only process k2 when it starts with an "A", this is the wildcard functionality you are looking for
//when k2 does not start with an "A" the logic will drop through
while $e(k2,1)="A" {

    //get first child key of k2
    set k3=$o(^G("ABC",k2,""))

    //loop on all child keys found
    while k3'="" {

        write !,k2," ",k3

        //get next child key of k2
        set k3=$o(^G("ABC",k2,k3))
    }

    //get the next k2 key
    set k2=$o(^G("ABC",k2))

}