Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi, how can I easily manage this code sample in tmap?
If(my_input.field1 > 6){
my_output.field1 = ...
else if
(my_input.field3 > 6 && my_input.field2 != null)
my_output.field1 = ...
my_output.field2 = ...
my_output.field3 = ...
my_output.field4 = ...
} else if{...
}
and so on.
Do I have to cover all the path in whitch my code will fall?
for example: (my_input.field6 > 6 && my_input.field3 < 6 &&
my_input.field2 == null)?first_if_block:(all condition meeting second block):etc???
This is quite unintuitive being used to manage all the case with java code
Hello @matteo marchesi
If you have different conditions for each column on your mapping, you'll have to cover all the path in each output column just like in your example.
To simplify complex conditions, you can use the Var section of tMap and create variables to store the test results.
Let's say you have a condition to identify a valid transaction using the example you provided:
my_input.field6 > 6 && my_input.field3 < 6 && my_input.field2 == null
Then you create a boolean variable on Var section called "valid_transaction", use the condition above there and then you can reuse this variable on the output columns instead of rewriting the same condition for each output column you need it.
It will become something like this:
Var.valid_transaction? first_if_block:(all condition meeting second block): etc...
Now, if you have the same conditions applying for all output columns, I suggest you use a "join table" output.
Click on the "add" icon on the upper right section of tMap window, select the option "Create join table from" and select an existing output.
Then you can define different conditions for each output schema using the expression filter, apply different transformations for each column of the schema and in the end, all these output schemas will be joined to a single tMap output row that is the output schema from which the others were derived.
This is the closest to an if-else structure like this:
If(my_input.field1== 1) {
my_output.field1 = my_input.field1
my_output.field2 = my_input.field2 * 10
my_output.field3 = my_input.field3 * my_input.field4
my_output.field4 = my_input.field4.substring(0, 9)
}
else if (my_input.field1 == 2) {
my_output.field1 = my_input.field1
my_output.field2 = my_input.field2 * 20
my_output.field3 = my_input.field3 * my_input.field2
my_output.field4 = my_input.field4.substring(10, 19)
}
Hello @matteo marchesi
If you have different conditions for each column on your mapping, you'll have to cover all the path in each output column just like in your example.
To simplify complex conditions, you can use the Var section of tMap and create variables to store the test results.
Let's say you have a condition to identify a valid transaction using the example you provided:
my_input.field6 > 6 && my_input.field3 < 6 && my_input.field2 == null
Then you create a boolean variable on Var section called "valid_transaction", use the condition above there and then you can reuse this variable on the output columns instead of rewriting the same condition for each output column you need it.
It will become something like this:
Var.valid_transaction? first_if_block:(all condition meeting second block): etc...
Now, if you have the same conditions applying for all output columns, I suggest you use a "join table" output.
Click on the "add" icon on the upper right section of tMap window, select the option "Create join table from" and select an existing output.
Then you can define different conditions for each output schema using the expression filter, apply different transformations for each column of the schema and in the end, all these output schemas will be joined to a single tMap output row that is the output schema from which the others were derived.
This is the closest to an if-else structure like this:
If(my_input.field1== 1) {
my_output.field1 = my_input.field1
my_output.field2 = my_input.field2 * 10
my_output.field3 = my_input.field3 * my_input.field4
my_output.field4 = my_input.field4.substring(0, 9)
}
else if (my_input.field1 == 2) {
my_output.field1 = my_input.field1
my_output.field2 = my_input.field2 * 20
my_output.field3 = my_input.field3 * my_input.field2
my_output.field4 = my_input.field4.substring(10, 19)
}
Hi @Anselmo Peixoto , kind as always.
I've tought on using variables in tMap to simplify the logic.
Didn't thought about the join tale in output.
Already with the variable thought it's way more readable. I'll evaluate the join options if I'll get more complex if-else.