Interacting with global variables

A global variable contains a value that can be used to pass information from one HATS object to another. For example, you can extract information from several locations on a host screen, perform calculations, and insert the result on the current screen or a future one. You can build up an array of strings from one or more host screens and insert them into a transformation. You can extract a string that a user enters into a field on the GUI and use it elsewhere.

Global variables that are only visible within the scope of a single HATS application are called local global variables. Global variables that are visible to and can be used by all HATS Web applications in the same .ear file, or by all HATS rich client applications running in the same rich client environment, are called shared global variables. Any time you use or create a global variable, you must specify whether it is local or shared. The Advanced settings section allows you to specify sharing. The default setting for all global variables is local.

Note:
Two global variables with the same name can coexist if one is local and the other is shared.

For HATS Web applications you can share global variables between applications within the same .ear file during a single HTTP session. For HATS rich client applications you can share global variables between applications running in the same rich client environment. If the rich client environment is closed and restarted, previously shared global variable values are not preserved.

A global variable can contain a numeric value, a string, or an indexed array of strings. If you use a global variable to contain an array of strings, you can specify for any action whether you want to use the entire array, a particular index, or all the values starting at a particular index. All operations on global variables are case-sensitive. Do not use names beginning with HATS, hats or Hats for global variables.

You can set the value of a global variable in these ways:

After a global variable has a value, you can use that value in the following ways:

If you insert a global variable into a host screen, you must list this action before applying a transformation, to ensure that the global variable will appear on the GUI created from the host screen. It might make sense however to insert a global variable into the host screen after a transformation returns and before the host screen is sent back to the host. See Actions for more information about specifying actions for screen events. For information about inserting global variables into transformations and templates, see Insert Global Variable.

Global variables can be used with prompt and extract macros either to provide a value for a prompt or to store a value extracted from the host screen. Global variables can be used in conjunction with macros to combine multiple host screens in a single GUI. See Macros and host terminal and Combining screens for more information about using global variables with macros.

You can override global variables to pass data from the GUI to the application. Local and shared global variables can be overridden. For more information, see Global variable overrides.

They may also be used for screen recognition. For more information , see Screen Recognition Criteria or Begin Screen.

For information about using global variables in business logic, see the HATS Web Application Programmer's Guide or the HATS Rich Client Platform Programmer's Guide, depending on your application environment.

If you want to use a global variable to accumulate strings or a numeric value from several screens, you can initialize it by adding a Set global variable action to the start or connect application event.

Double click on the Project Settings of your HATS project in the HATS Projects view. Go to the Events tab.

To set global variables in the connect event, double-click Connect to open the event editor. Then you can add the global variable on the Actions tab. This way, the global variable is linked with the action being performed.

The same can be done for the Start event.

You can remove local and shared global variables using the Remove global variable action on a screen event or application event. For more information, see Remove global variable action.

Renaming global variables

You can rename each instance of a global variable. To get a list of all global variables found in a particular HATS project take the following steps:

  1. Select Window > Show View > HATS Global Variables from the HATS menu bar. The HATS Global Variables view will be placed right below the Palette view.
  2. Click on a project in the HATS Projects view to populate the HATS Global Variables view with all the global variables found in the selected project's macros and events. If you select a different project, the HATS Global Variables view will be updated. The content is refreshed when a macro or event of the selected project is added, deleted, or edited.
  3. You can rename a global variable through the HATS Global Variables view by right clicking the global variable to edit the name. You can also double-click on the macros or events listed under each global variable to open them. When you create or edit the macros or events, the HATS Global Variables view will automatically be updated.
Note:
Renaming global variables is only supported for global variables defined in macros and events; therefore, the HATS Global Variables view will only display those global variables. Renaming global variables will not rename the global variables in business logic, transformations or elsewhere in your HATS project.

Differences between global variables and macro variables

In HATS, there are two main types of variables; global variables and macro variables. The differences between them are outlined here.

Global variables

Global variables are variables created in HATS Toolkit and used by HATS projects. Global variables are stored outside of the macro script in the HATS .hma source file. They are maintained and updated by HATS runtime. There are two types of global variables:

Local
A local global variable is one that is created within a HATS project, and is only visible to the project.
Shared
A shared global variable is one that is visible to and can be used by all the Web applications in an .ear file or by all rich client applications in a rich client environment.

Whether a global variable is considered local or shared depends on whether the Shared check box in the GUI is selected when the global variable is created, or whether the value of the shared attribute of a set, prompt, or extract tag is specified as yes or no in the HATS .hma source file.

Macro variables

Macro variables are variables created in the Visual Macro Editor or the Advanced Macro Editor. Macro variables are internal to macros. They are not used outside of macros. Macro variables are created, stored, and used by the macro engine, and listed in the macro script. For more information about macro variables, see the chapter, Variables and imported Java™ classes, in the HATS Advanced Macro Guide.

In the source of a HATS macro (.hma) file that uses HATS prompts and extracts for global variables, the prompts and extracts are contained in the source file before the macro script. The macro script syntax is enclosed by the <HAScript> and </HAScript> tags.