Question
· Feb 19, 2023

Export Data lookup table into list of Strings

is it possible to export a specific data lookup table (Ens_Util.LookupTable) directly into Recordmap or Request message class or just a list of strings for me to loop through them?

Trying to find an optimal solution for a high volume interface.

Product version: IRIS 2022.1
Discussion (1)1
Log in or sign up to continue

// Hugging the Globals for a fast ride

set tableName="MyTableName"
set key=""
for {
    set key=$Order(^Ens.LookupTable(tableName,key),1,value)
    quit:key=""
    Write !,key,"=",value
}

// As export string method with delimiters ":" and ";"

 classmethod ExportTableAsString(tableName) as %String
{
  set (ret,key)=""
  for {
    set key=$Order(^Ens.LookupTable(tableName,key),1,value)
    quit:key=""
    set ret=ret_key_":"_value_";"
  }
  quit $E(ret,1,*-1)
}

// As export array method

classMethod ExportTableAsArray(tableName,OUTPUT ary)
{
  kill ary
  merge ary=^Ens.LookupTable(tableName)
}
----------------
do ##class(Someclass).ExportTableAsArray("MyTable", .ary)

// If you want to iterate over a slice of keys for example All keys prefixed with "Q" set tableName="MyTableName"

set (key,prefix)="Q"
for {
    set key=$Order(^Ens.LookupTable(tableName,key),1,value)
    quit:key=""
    quit:prefix'=$E(key)
    Write !,key,"=",value
}

// To confirm existence of a key in a lookup table

if $Data(^Ens.LookupTable(tableName,someKey)) {
  Write !,key,"=",^Ens.LookupTable(tableName,someKey)
}

// To dump the lookup table to terminal

zwrite ^Ens.LookupTable(tableName)

The top node of the LookupTable has a timestamp, so it is possible you could use this to setup / invalidate an external cache of lookup values.

Hope this gives some ideas.