cancel
Showing results for 
Search instead for 
Did you mean: 

Concatenating two same fields

Former Member
0 Kudos

Hi Experts,

Is it possible to concatenate the same field at mapping level and mapped to target field?

Please consider the sample scenario where I have segment S1 which contain Field F1 at source side which may appear twice with different values and both values need to be concatenate and mapped to Field F2 at Target Segment S2. How to achieve the same?

Example

Source Side

<S1>

     <F1>This sample text1</F1>

</S1>

<S1>

     <F1>This sample text2</F1>

</S1>

mapping logic should contact both and map to target (which should look like below one)

<S2>

     <F2>This sample text1 This sample text2</F2>

</S2>

Regards

Faisal

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello,

Write a UDF.

Execution type: all values of a context

Input var1

String total = "";

for(int i=0;i<var1.length;i++)

{

total = total + var1[i];

}

result.addValue(total);

Mapping

F1 ---Remove Context -- UDF--- Output

Note - check for any syntax errors + corrected type error.

Thanks

Amit Srivastava

Message was edited by: Amit Srivastava

Answers (1)

Answers (1)

former_member184720
Active Contributor
0 Kudos

use the below UDF and pass the your field to it

String out = "";

for(int i=0;i<var1.length;i++)

{

out = out+var1[i];

}

result.addValue(out);

field -> remove context>above UDF

Former Member
0 Kudos

Hello Hareesh,

How ur answer is different than mine?

IMO, there is no need to post same answer which was already shared above.

Thanks

Amit Srivastava

former_member184720
Active Contributor
0 Kudos

Hello Amit - May be you could have noticed the time difference too.. If i had looked at your reply i don' think i can post something in a min gap..

However I was trying to edit my response and update the same.. which i did in many instances..

As you have replied, i was unable to edit it..

P.S : just noticed.. i think it should be total = total + var1[i]; instead of total = total + var1[0];  which is not a syntax error i believe..

Former Member
0 Kudos

Hello Hareesh,

Yaa, just now noticed the time difference which was actually becoz i have added this line -

Note - check for any syntax errors

But anyway, good to know that u are following guidelines.

Thanks

Amit Srivastava

Former Member
0 Kudos

>>i think it should be total = total + var1[i]; instead of total = total + var1[0];  which is not a syntax error i believe..


Yes, ur assumption is true it's not a syntax but a typo error