Geoffrey Smullen · Dec 28, 2016

How do I create a List of a subset of routines from the ^$ROUTINE global?

I want to generate a list object of routines from the ^$ROUTINE global without directly reading the [^$ROUTINE] global.

E.G. I want to create an array/variable/object with names of all routines that start with "ABC" so that an application process can use each routine name as input for a subsequent process.

0 604
Discussion (3)0
Log in or sign up to continue

Is there any specific reason for not wanting to use the RoutineList() query from the %Library.Routine class?

query RoutineList(spec As %String(MAXLEN=512), dir As %Integer, type As %Integer, nsp As %String)

    This query provides a list of all routines that match the pattern specified by spec.

    spec may contain both * and ? as wildcards. It may also consist of more than one, comma-delimited selections. For example:
    dir specifies the direction to search in, 1 is forwards and -1 is backwards.
    type is 1 to include OBJ files in the search and the default, 0 will just include INT, MAC, INC, BAS.
    nsp is the namespace to list from. If omitted, the query returns the routines from the current namespace. nsp can be either an explicit or an implied namespace. 

Your request could then be implemented with a simple call like:

 s tRS=##class(%ResultSet).%New("%Routine:RoutineList")
 d tRS.Execute("ABC*.INT")
 f  q:'tRS.Next()  s routName=tRS.GetData(1) w "Found ",routName,!

I would recommend to use a bit modern way

set rs=##class(%Routine).RoutineListFunc("ABC*.int")
while rs.%Next() {
  write !,rs.Name

Thank you, Stefano & Dmitry.

To answer Stefano's question about avoiding direct reference of ^$ROUTINE...I'm learning ObjectScript and moving off of (plain old) M and was looking for a way to abstract the code from ^$ROUTINE global.