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 a Web page and use it elsewhere.

You may share global variables across applications (within the same EAR) during a single HTTP session. Global variables that can be shared between applications are called 'shared global variables', where as global variables that are only visible within the scope of a single HATS application are called 'local variables'. Any time you use or create a local global variables, you need to specify whether it is a shared or local. The Advanced settings section will allow 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.

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:

  • With a Set global variable or Extract global variable as an action on a screen customization or other event

  • By prompting the user for a value in a transformation JSP

  • By prompting the user for a value while running a macro

  • By setting a value in the macro source code

  • By setting the value in a business logic program.

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

  • To calculate the value of another global variable, in a Set global variable action

  • To write the value to a host screen, using an Insert Data action

  • To insert the value into a transformation or a template, using the Insert Global Variable menu item

  • To pass the value to a macro

  • To use the value in business logic

  • To use as a criterion in screen recognition.

If you insert a global variable into a host screen, list this action before applying a transformation, so that the global variable will appear on the Web page 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 customizations. For information on inserting global variables into transformations and templates, see Insert Global Variable.

Global variables can be used with prompt and extract macros to either 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 JSP. See Macros and Host Terminal for more information about using global variables with macros.

You can override global variables to pass data from the browser 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.

To use global variables in business logic, see the HATS Programmer's Guide

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 event.

Double click on the Project Settings of your HATS project in the HATS Project 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 in the Action tab. This way, the global variable is linked with the action being performed.

The same can be done for the Start event.

Renaming global variables

When you rename an instance of a global variable within a HATS application, only that particular instance of the global variable is renamed. HATS V6 has added ability to rename all instances of a global variable. To get a list of all global variables found in a particular HATS project do the following:

  1. Select Window > Show View > Global Variables from the HATS toolbar. The Global Variables view will be placed right below the Palette view.

  2. Click on a project in the HATS Project View to populate the view with all the global variables found in the selected project's macros and events. If you select a different project from the HATS Project View, the 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 the global variable through the view toolbar menu or by right clicking the global variable to edit the name. You can also can double-click on the macros or events listed under each global variable open them When you create or edit the macros or events, the Global Variables view will automatically be updated.
Note:
Renaming of global variables is only supported for global variables defined in macros and events; therefore, the Global Variables view will only display those global variables. Also, 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 Studio 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 applications in an .ear file.

Whether a global variable is considered local or shared depends on whether the shared check box in the GUI is checked 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 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.

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.