cancel
Showing results for 
Search instead for 
Did you mean: 

JAVA UDF -- For Concatenation from same context in SAP PI

pr_srinivas
Contributor
0 Kudos

Hi Experts,

From the below screenshot - its one to one mapping - however we need to concatenate values from the display queue and process to target filed with comma saparate - In this below example

output :

10MG,20MG,40MG, 50 MG ...etc.

can you help with JAVA udf.

Regards,

Accepted Solutions (0)

Answers (5)

Answers (5)

pr_srinivas
Contributor
0 Kudos

its very simple code...with queue context

int i=ProductID.length;

result.addValue(ProductID[i-1]);

it works thanks..

former_member607993
Contributor
0 Kudos

Goog. Yes you can get the last value of the context.

//get last value of the context

int x;

String y = "";

x = personNumber.length;

y = personNumber[x-1];

result.addValue(y);

Thanks!

pr_srinivas
Contributor
0 Kudos

Hi Rajesh,

Thank you for your prompt response. Here scenario is little different. we are getting the values in multiple line item and if you look the queue values as below.

in output - we need to write only last values 10,20,40 in target field.

anupam_ghosh2
Active Contributor
0 Kudos

Hi sakriyanaik.nk,

The code of rajeshps will work perfectly fine. Just use remove context for the input field (String[] personNum) before calling the UDF in mapping.

Regards

Anupam

pr_srinivas
Contributor
0 Kudos

Hi Rajesh,

This works - small change require in code in output we are getting below.

10,

10,20,

10,20,30,

10,20,30,40, and so on.

----

in the above scenario - we need to process last line i:e 10,20,30,40 and so on remaining above ignore.

-----

former_member607993
Contributor
0 Kudos

Hello sakriyanaik.nk,

You can use below UDF to add commas after each context.

public void addComma(String[] personNum, ResultList result, Container container) throws StreamTransformationException{

String target="";

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

{

target = target+personNum[i];

if (i != personNum.length-1)

{

// if i not equal to personNum.length -1

target = target+"," ;

}

result.addValue(target);

}

Thanks,

Rajesh PS