Using Variables

www.altova.com Print this Topic Previous Page Up One Level Next page

Home >  Designing Mappings >

Using Variables

Variables are a special type of component used to store an intermediate mapping result for further processing. They might be necessary in situations where you want to temporarily "remember" some data on the mapping and process it in some way (for example, filter it, or apply some functions) before it is copied to the target component.

 

Variables can be of simple type (for example, string, integer, boolean, etc) or complex type (a tree structure).

mf_variable_simple

Simple variable

You can create a variable of complex type by supplying an XML schema which expresses the structure of the variable. 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 any associated instance XML file; the data of the variable is computed at mapping runtime.

mf_variable_complex_schema

Complex variable created from an XML schema

It is also possible to create variables of complex type from databases. In case of databases, you can choose a specific database table as root item for the variable structure.

mf_variable_complex_db

Complex variable created from a database table

In the images above, you may notice that 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 on the mapping (see Changing the Context and Scope of Variables).

 

When necessary, items of a variable structure can be duplicated to accept data from more than one source connection, similar to how this is done for standard components (see Duplicating Input). This does not apply, however, to variables created from database tables.

mf_variable_simple_duplicated

Simple variable with duplicated inputs

One of the most important things about variables is that they are sequences, and can be used to create sequences. The term "sequence" here means a list of zero or more items (see also Mapping Rules and Strategies). This makes it possible for a variable to process multiple items for the duration of the mapping lifetime. If, however, you want to assign a value once to a variable and keep it the same for the rest of the mapping, it is also possible (see Changing the Context and Scope of Variables).

 

To some extent, variables can be compared to intermediate components of a chained mapping (see Chained Mappings). However, they are more flexible and convenient if you don't need to produce intermediary files at each stage in the mapping. The following table outlines differences between variables and chained mappings.

 

Chained mappings

Variables

Chained mappings involve two totally independent steps. For example, let's assume a mapping that has three components A, B, and C. Running the mapping involves two stages: executing the mapping from A to B, and then executing the mapping from B to C.

While the mapping is executed, variables are evaluated according to their context and scope. Their context and scope can be influenced (see Changing the Context and Scope of Variables).

When the mapping is executed, intermediate results are stored externally in files.

 

When the mapping is executed, intermediate results are stored internally. No external files containing a variable's results are produced.

The intermediate result can be previewed using the preview btn_component_preview_pressed button.

A variable's result cannot be previewed, since it is computed at mapping runtime.

 

Note:Variables are not supported if the mapping transformation language is set to XSLT 1.0.

© 2019 Altova GmbH