Using Global Variable

Global variables are used for mapping source elements, mapping functions or constants to target elements. They are declared and used globally for all target elements.

To use a global variable in a mapping activity, you need to map it to a target element. This will successfully execute the global variable when you execute the mapping activity in the process flow.

A global variable differs from a context variable, in the respect that it is available only within the selected mapping activity. Context variables are available in the process designer too.

Declare Global Variable

Steps to declare a Global Variable

  1. Ensure that the source and target schemas are loaded and all their elements are listed under their respective nodes.
  2. Click the Global tab in the Mapping Graph Area. All tabs of the Global tab are displayed.
  3. Click the Global Variables tab. The Global Variable pane is displayed in the Mapping Graph Area (see Figure 520). 


    Figure 520: Global Variable Pane

  4. Click the Global Variable Name text field and enter the name of the global variable you want to create (e.g. emp_age). Press the Tab or Enter key. This takes the control to the Global Variable Value field.
  5. Enter the value of the global variable in the Global Variable Value field. You can enter the value of the global variable using one of the listed methods:
     
    • Click required source element
    • Select the required Mapping function
    • Type the required value manually
    • Select a Custom Method

      To select a Custom Method as the value of a global variable, double click the desired Custom Method under Custom Methods in the Parameters Panel. The selected Custom Method is displayed in the Variable Definition field.

      To learn how to declare a Custom Method, refer to section Using Custom Method.

  6. Enter comments for the global variable in the Add Comment field (see Figure 521). For example, if the global variable value contains complex XSLT logic, you can enter its description in this field.

    The Comments field is resizable.


    Figure 521: Enter Name, Value and Comments of Global Variable

     

  7. Click Save Global Variable (  ) button to save the global variable. This global variable is added to the list of existing variables in the Global Variable Name field. It is also displayed under Global Variables in the Parameters Panel. If you shift the focus to another node, or click any of theMapping Rules, Textual Rules, Local Variables, Properties, XSL or Debugger tabs, without saving the global variable, an alert message is displayed. (see Figure 522). The comments added for the global variable are saved and displayed above the global variable declaration in the Mapping XSL (refer to Figure 523).


    Figure 522: Alert Message

    For example, you have defined a global variable Var1, and you click the Name target element, without saving Var1, then the alert message is displayed.

    The alert message is also displayed when shifting focus between Global and Node tabs.

  8. Click No to save the global variable and shift the focus to the other object. If you click Yes, then the defined global variable is cleared and the focus is shifted to the other object.


Figure 523: Comment in Mapping XSL

You can rearrange the global variables by dragging it up or down in the list.

To remove a global variable, select the global variable and click Remove selected global variable () button.

To remove all global variables, click Remove all global variables () button.

 

 

  Managing a Global Variable from the Parameters Panel
Once the global variable is added to the Parameters Panel, you can edit it or delete it anytime from this Panel itself. 
 

Steps to manage a Global Variable from the Parameters Panel

  1. Right-click the global variable that you want to edit or delete. This displays the right dropdown menu (see Figure 524).

    Figure 524: Right-Click menu of Elements in Parameter Panel

  2. Select Edit to edit the variable. This displays the selected global variable in Edit mode. You can edit the value of the global variable in the Global Variable Value field. You can also edit the name of the global variable.
  3. Alternately, select Remove to delete the selected variable. This displays a confirmation screen for the delete operation (see Figure 525).

    Figure 525: Confirm Delete of Global Variable

  4. Click Yes to delete the selected variable.

  
Map Global Variable to Target Element
Once you have created a global variable, you can map it to a target element. 
 

Steps to map Global Variable to target element

  1. Ensure that the source and target schemas are loaded and all their elements are listed under their respective nodes.
  2. Click the Node tab displayed in the Mapping Graph Area. All tabs of the Node tab are displayed. Click Mapping Rules tab.
  3. Select a target element. This displays the selected target element node in the Mapping Graph Area.
  4.   Double-click the required global variable under Global Variables in the Parameters Panel. The selected global variable node is displayed in the Mapping Graph Area (see Figure 526).

    Figure 526: Add Global Variable Node

  5. Create a link from the output of the global variable to the input of the target element.
  6. Click the Apply Mapping (  ) button. This maps the global variable to the target element. If you shift the focus to another target element, or click any of the Node, XSL or Debugger tabs, without applying the mapping, then an alert message is displayed. (refer to Figure 522).
  7. Click No to apply the mapping and then shift the focus to the other object. If you click Yes, then the mapping activity is cleared and is replaced by the previous mapping in the Mapping Graph Area and the focus is shifted to the other object.

    Once a global variable is mapped to a target element, the letter (M) is displayed next to the mapped target element. This signifies that a target element has been mapped. Refer to Table of Suffixes for details on suffixes displayed next to a target element.

  8. Save the mapping activity and exit the Data Mapper.