tSetGlobalVar - 6.1

Talend Components Reference Guide

EnrichVersion
6.1
EnrichProdName
Talend Big Data
Talend Big Data Platform
Talend Data Fabric
Talend Data Integration
Talend Data Management Platform
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for Big Data
Talend Open Studio for Data Integration
Talend Open Studio for Data Quality
Talend Open Studio for ESB
Talend Open Studio for MDM
Talend Real-Time Big Data Platform
task
Data Governance
Data Quality and Preparation
Design and Development
EnrichPlatform
Talend Studio

tSetGlobalVar properties

Component family

Custom Code

 

Function

tSetGlobalVar allows you to define and set global variables in GUI.

Purpose

tSetGlobalVar facilitates the process of defining global variables.

Basic settings

Variables

This table contains two columns.

Key: Name of the variable to be called in the code.

Value: Value assigned to this variable.

Advanced settings

tStatCatcher Statistics

Select this check box to gather the Job processing metadata at a Job level as well as at each component level.

Global Variables

ERROR_MESSAGE: the error message generated by the component when an error occurs. This is an After variable and it returns a string. This variable functions only if the Die on error check box is cleared, if the component has this check box.

A Flow variable functions during the execution of a component while an After variable functions after the execution of the component.

To fill up a field or expression with a variable, press Ctrl + Space to access the variable list and choose the variable to use from it.

For further information about variables, see Talend Studio User Guide.

Usage

This component is generally used as a one-component subjob.

Log4j

If you are using a subscription-based version of the Studio, the activity of this component can be logged using the log4j feature. For more information on this feature, see Talend Studio User Guide.

For more information on the log4j logging levels, see the Apache documentation at http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html.

Limitation

Knowledge of Java language is required.

Scenario: Printing out the content of a global variable

This scenario is a simple Job that prints out the value of a global variable defined in the tSetGlobalVar component.

Setting up the Job

  1. Drop the following components from the Palette onto the design workspace: tSetGlobalVar and tJava.

  2. Connect the tSetGlobalVar component to the tJava component using a Trigger > OnSubjobOk connection.

Configuring the tSetGlobalVar component

  1. Double-click the tSetGlobalVar component to display its Basic settings view.

  2. Click the plus button to add a line in the Variables table, and fill the Key and Value fields with K1 and 20 respectively.

  3. Then double-click the tJava component to display its Basic settings view.

  4. In the Code area, type in the following lines:

    String foo = "bar";
    String K1;
    String Result = "The value is:";
    
    Result = Result + globalMap.get("K1");
    
    System.out.println(Result);
    
    

    In this use case, we use the Result variable. To access the global variable list, press Ctrl + Space bar on your keyboard and select the relevant global parameter.

Job execution

Save your Job and press F6 to execute it.

The content of global variable K1 is displayed on the console.