Generate a fixed number of occurrences

Expressions are used mainly to perform mappings on data. The integration engine picks up and combines elements from the input data to generate new output data. This is accomplished by binding an expression to each of the nodes of the output Business Document.

In the previous chapters of this guide, you saw structures that operate on constants, variables or input data and how to deal with multiple occurrences of data in input nodes.

Now you have to conceive a DML Block whose task is to perform the following mapping:

Mapping example

The task here is to clone the single incoming set of data to fill two mandatory occurrences of segment s; data fields a, b and c are copied verbatim. The output Business Document is defined as follows:

s1..n
a1..1, class s
b1..1, class s
c1..1, class s

Instructing the integration engine to copy input nodes a, b and c to the output nodes with the same names is easy: just define a Map with the expressions:

Output Node Bound
expression

a

\a

b

\b

c

\c

This Map lacks something essential: a way to specify that you want to generate two occurrences of segment s.

To instruct the integration engine to do this, you invoke the times instruction in the expression bound to node s:

Node Bound
expression

s

2 times

a

\a

b

\b

c

\c

The times statement is composed of the reserved word times preceded by a whole number (class I) value expression. When processing this statement, the integration engine computes the frontal expression value and then generates that number of occurrences.

The times statement does not generate a value. Its function is to calculate a number of occurrences. Such a statement is known as a cardinality statement. It can only be bound, in Maps, to a node with cardinality 0..1, 0..n or 1..n.

Cardinality statements are required when the integration engine cannot determine itself how many occurrences of a node must be created. This is quite obvious for multiple nodes (0..n and 1..n). For optional nodes (0..1) it is more subtle. For nodes defined having value, as far as an expression is bound to the node, it is generated. For nodes defined not having value, you must bind an expression with a time statement if you want an occurrence of that node to be generated.

When dealing with a node that is both multiple and defined as having value, you need to tell the integration engine not only to generate a certain number of occurrences, but also to set the value of each occurrence. This is accomplished using the times…do instruction. Enhance your example with the new output Business Document defined as follows:

s1..n, class i
a attribute, 1..1, class s
b attribute, 1..1, class s
c attribute, 1..1, class s

What changes here, is that the segment holds a number (the first occurrence is 1 and the second is 2) and a, b and c are now attributes. You must use times…do in conjunction with a variable in order to number the segments:

Output
node
Bound expression

s

2 times do { %index := %index + 1; %index }

a

\@a

b

\@b

c

\@c

The integration engine continues to generate two occurrences of the s node, but each time a new s is created, the block enclosed in curly brackets is evaluated. When the variable index has an initial value of 0, the block evaluates to 1 for the first occurrence of s and 2 for the second.

The following graphic shows how output data is generated using input:

Example: how output data is generated using input

Data fields are cloned and the segment numbered.

When used on a node that groups other nodes, you tell the integration engine to generate the group several times. As many occurrences as needed of all group members are generated.

Related Links