HATS Tricks

1 Posts tagged with the variable tag
1

How to use Global Variables to populate Macro Variables in a HATS Transformation Macro

If you want to populate a macro variable with a global variable value, there is an easy way to do so.
The first step is to make sure that there is a global variable to prompt from.

Create a Global Variable

  1. In your screen customization, go to the Actions tab.
  2. Choose Add and select Set Global Variable.
  3. Name the global variable and give it an initial value so that we can use it in the macro later.
  4. Click Finish and make sure that the actions are in the proper order (the Set Global Variable should be before the Play Macro).
http://www-949.ibm.com/software/rational/cafe/servlet/JiveServlet/downloadImage/38-1197-1553/setGlobalVariable.JPG
Now we need to make sure that your macro is set up to work with macro variables, and that the macro has a macro variable available to work with.

Create a Macro Variable

  1. Open up the macro with the Visual Macro Editor.
  2. Right click on the screen and choose properties.
  3. In the properties panel choose Variables and Types.
  4. Make sure the choice for Enable support for variables and arithmetic expressions is enabled.
  5. If you have a macro variable, make sure it is available, otherwise create a macro variable on this page.
  6. To create a macro variable, click Add and give the variable a name (you do NOT need $ symbols around the name for this wizard) and a value (string values require single quotes) and press Finish.
http://www-949.ibm.com/software/rational/cafe/servlet/JiveServlet/downloadImage/38-1197-1554/addMacroVar.jpg
This macro variable will show in the source view as
<vars>
<create name="$testMV1$" type="string" value="'hello world!'"/>

</vars>
Now that we have a valid macro variable, we can use it in the prompt action.

Create a Prompt Action

  1. In the macro, create a new prompt action using the Visual Macro Editor. In the macro main view, right click on the screen that you wish to modify and choose properties.
  2. Choose Actions. In the actions table, choose Add. When given the choice of what action to add, choose Prompt.
  3. In the Prompt panel, name the prompt, select save value to variable and choose the correct macro variable. Make sure to enable Do not insert value into field unless it was specifically your intention to do otherwise. For the handler, choose Set prompt to global variable and choose the correct global variable. Press Finish and make sure that the new prompt action is in the correct place in the list.
http://www-949.ibm.com/software/rational/cafe/servlet/JiveServlet/downloadImage/38-1197-1555/add+macro+prompt+steps.jpg
In the source view you can see that the following action was added to the screen.
<prompt assigntovar="$testMV1$" clearfield="false" col="0" default="" description="" encrypted="false" len="80" movecursor="false" name="'gv_to_mv'" required="false" row="0" title="" varupdateonly="true" xlatehostkeys="false"/>
Note that the assigntovar parameter has the macro variable name with the $ symbol surrounding the macro variable name. Also notice that the varupdateonly parameter in the prompt action was set to true, so that we will not accidentally change the host screen.
We are finished, and now can get our global variable value to our macro variable!

Next time I will cover how to copy data in the other direction, from a macro variable to a global variable.

1 Comments Permalink
Bottom Banner