Variables
A variable is a special type of components used to store an intermediate mapping result for further processing. Variables can be of simple type (e.g., string, integer, boolean, etc) and complex type (a tree structure). See the examples of both types in the subtopics below.
One of the most important aspects of variables is that they are sequences and can be used to create sequences. The term sequence means a list of zero or more items. This makes it possible for a variable to process multiple items for the duration of the mapping lifetime. For more information, see also Mapping Rules and Strategies. However, it is also possible to assign a value to a variable once and keep this value the same for the rest of the mapping. For details, see Changing the Context and Scope of Variables.
For details about how to add a variable to a mapping, see Add a Variable.
Simple variables
A simple variable is built to represent atomic types such as strings, numbers, and booleans (see screenshot below).
Complex variables
A complex variable has a tree structure. The structures on which a complex variable can be based are summarized in the list below.
MapForce Basic Edition:
•XML Schema Structure
MapForce Professional Edition:
•XML Schema Structure
•Database Structure
MapForce Enterprise Edition:
•XML Schema Structure
•Database Structure
•EDI Structure
•FlexText Structure
•JSON Schema Structure
Example 1: Variable based on XML Schema
You can create a complex variable by supplying an XML schema which defines the structure of the variable (see screenshot below). If the schema defines any elements globally, you can choose which one should become the root node of the variable structure. Note that a variable does not have an associated instance XML file. The data of the variable is computed at mapping runtime.
Example 2: Variable based on a database (MapForce Professional and Enterprise editions)
If you choose a database structure for your variable (see screenshot below), you can choose a specific database table as the root item for the variable structure. MapForce allows you to create DB-based variables with a tree of related tables.
The tree of related tables represents an in-memory structure that has no connection to the database at runtime. The variable only describes the structure but does not do anything with the data. This implies the following:
•No validation based on the data type
•No possibility to use the SQL WHERE filter
•No table actions in parameters or variables
•No automatic handling of foreign keys
•No primary/foreign key checks
Compute-when
In both examples above, each variable has an item called compute-when. Connecting this item is optional: This enables you to control how the variable value should be computed in the mapping. For more information, see Changing the Context and Scope of Variables.
Variables with duplicated inputs
When necessary, items of a variable structure can be duplicated to accept data from more than one source connection. This is similar to duplicating inputs in standard components. The screenshot below illustrates a simple variable with duplicated inputs.
Chained mappings vs. variables
Variables can be compared to intermediate components of a chained mapping. However, variables are more flexible and convenient if you do not need to produce intermediary files at each stage of the mapping. The table below outlines differences between variables and chained mappings.
Chained mappings | Variables |
---|---|
Chained mappings involve two independent steps. For example, a mapping has three components, namely A, B, and C. Step 1: mapping data A to B. Step 2: mapping data from B to C. | You can control when and how often the variable value is computed when the mapping is carried out. For details, see Changing the Context and Scope of Variables. |
When the mapping is carried out, intermediate results are stored externally in files.
| When the mapping is carried out, intermediate results are stored internally. No external files containing the results of a variable are produced. |
The intermediate result can be previewed using the preview button. | The result of a variable cannot be previewed, since it is computed at mapping runtime. You can, however, use the debugger to see the data produced by the variable. |
Note: | Variables are not supported if the mapping transformation language is set to XSLT 1.0. |