Question
· Feb 4, 2020

Caché Studio : How to find and record all global variables referenced in routine or collection of routines?

I am looking to run some analysis on existing software to quickly identify global variable references. Ideally you would feed in a "starting routine" and after going through all referenced routines you would end up with a finite set of global variables. So the primary purpose is to take say 10,000 lines of code and map out the referenced global structures without relying on a programmers eye. I found the post on Object Script equivalent to Studio "Find in Files" interesting but the downside is that output is too verbose and would require parsing to extract the global structures. How would you override writing to the terminal so that you could parse the data?

The Find & Replace option in Caché Studio is also interesting as it allows you to filter by Language=Cache ObjectScript and Element=Global Variable. You can also change the scope to Element=Routine to identify routines  but unfortunately 'Find What' is mandatory so there appears to be no option to simply find all Routine calls within the current document without a search prefix.

The example below is for finding all references to % Routines within the currently opened document

Could you achieve a similar result from the terminal with the output being a simple collection of either routine names or global variable names? 

Discussion (4)0
Log in or sign up to continue

Recommended approach - always use macros for al your GLVN needs (see: DeepSee, %Dictionary). This way reporting is easy - just open inc file and you're done.

%Compiler package contains Traveler/Visitor implementation for ObjectScript but it's not officially supported - use at your own risk.

Although the task is unfortunately unsolvable at compile-time due to the abundant meta programming, such as indirection and xecute.

In your proposed solution you can enable checkbox "Use Wildcards" in Find & Replace and search for * which is essentially everything.

Statistical performance metrics isn't what I'm looking for. Rather than a simple number or metric, I'm looking to actually map global structures - similar to what the journal is doing with sets and kills but for a specific routine or set of routines. Also some code doesn't execute but it is still important to identify references to globals.

Stephen,

This may be far more than you were looking for, but I will share what I did to determine what globals were being accessed in the VA VistA software.

The first step was to convert the routines to the CSV version using the %SyntaxColor class in Cache.  This link shows an example: https://www.bmirwin.com/vnode/RoutineDg/MainDisplay.php?routine=IB20E540.  The top frame is the routine and the bottom frame is the CSV version of the routine.  If you look at line 9 of both frames you can find the global ^IBA referenced.  In the CSV version it is identified by the COS 12 indicator.  Therefore, to find all the global references in a list of routines just looking for the COS 12 indicators will find them.

This link https://www.bmirwin.com/vnode/dg/index.php?ns=IB20E shows a listing of a group of routines.  The "ns" variable can be changes to look at any routine or set of routines within the system.

Let me know if you would like more information.

Ben Irwin

ben1irwin@outlook.com