Calculation Fields

See also section Calculation Nodes and Fields.

Sometimes it is necessary to perform calculations in the mapping, whereby the affected substructures must not be visible in the output data.

Example: The number of order items must be specified in the header data of an order. The count is determined with a variable by creating a counting node with a path to the Position node in the source structure. The counting node contains a field counterPos that increases the counter with each iteration with a function. We do not want this part of the destination structure/tree to appear in the output data. This can be achieved by setting the attribute Calculation field to Yes for the field.

The following figure shows the effect of calculation fields on the destination tree.

images/download/attachments/34214085/Berechnungsfeld-version-1-modificationdate-1553578681000-api-v2.png

(1) We create a new node counting above the node OrderHeader in the destination structure. The node gets the same value for attribute Path as node Position. This repeats node counting as often as node (4).

(2) We create the field counterPos. The attribute Calculation field is set to Yes for this field. We use function calculate and save variable(a,b,c,d,[e]) on this field with parameter a=var__COUNTERPOS, b=+ and c=1. This will increment the value of variable var__COUNTERPOS each time the function is executed. So after the last iteration, the value of the variable will be equal to the number of order items.

(3) We create the field positions. We use function copy(field/value/variable) with parameter a=Variable var__COUNTERPOS. So the field will contain the number of positions.

(4) Node Position (in the destination structure) with a path to node Position in the source structure.

(5) Node counting will be iterated as many times in the destination tree as node Position. Since there is no 'real' field in this node, it will be ignored when the output data is created.

It is also possible to mix calculation fields and normal fields in any order within nodes. However, nodes containing normal fields will no longer be ignored when output files are created.