My preferred approach is using a Query class element.

Here's how it can look like:

Class Sample.Person Extends %Persistent
{

Property Name As %String;

Query ByName(name As %String = "") As %SQLQuery
{
SELECT ID, Name
FROM Sample.Person
WHERE (Name %STARTSWITH :name)
ORDER BY Name
}

ClassMethod Try(name)
{
  set rset = ..ByNameFunc(name)
  do rset.%Display()
}

}

Short and concise.

Easy to do that.

Here's how.

First of all let's find out where we do the iteration. If we open UtilExpGlobalView.csp we see that it's essentially a wrapper over %CSP.UI.System.GlobalViewPane.

In %CSP.UI.System.GlobalViewPane there's a LoadGlobal method which has this promising line:

Set tRS = ##class(%ResultSet).%New("%Global:Get")

Next we follow the trail to %Library.Global class implementing  Get query, which has GetFetch method, which actually iterates over the global here:

Set idx=$Order($$$ISCQUERYTEMP(Index,idx),1,Row)

So now we wrap it up back.

We need a new query (GetFetch is copied as is with one change - inverse iteration order, bolded):

 
Test.Global class

Now we wrap it into a pane

 
Test.GlobalViewPane

And finally create a csp page

 
UtilExpGlobalViewR.csp

And done, add R to URL and see the global in reverse in SMP:

Hello!

Can you elaborate on your high-level use case:

  1. What data are you storing?
  2. What do you want to calculate?

Any particular reason you  decided to use globals instead of tables/classes? Article on how globals/tables/classes interact.

In general your task can be solved in two mainstream and one additional way:

  1. Store f. Every time a data point is inserted/updated we calculate and store f(datapoint). Advantage: fast querying and savings on CPU cycles as the calculation work is only performed once. Disadvantage: changing f requires recalculation and time, storage.
  2. Calculate f. Every time data point is accessed we calculate f. Advantage: zero costs to change f, we immediately get new results. No storage required. Disadvantage: potentially CPU intensive load.

Additionally if you need to just check a condition (i.e. that f>0) you may not need an f value as by applying functional analysis, you can solve the issue analytically if f is a continuous function.

Open role as an object (note lowercase):

set role = "%db_cachetemp"
set roleObj = ##class(Security.Roles).%OpenId(role)

Create required resource as an object:

set resouceObj = ##class(Security.Resource).%New()
/// set resource

Insert resource into the role and save the role

do roleObj.Resources.Insert(resourceObj)
set sc = roleObj.%Save()

And role has a new resource.