Skip to Content

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

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,

concatanate.jpg (21.9 kB)
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Posted on Jul 03, 2020 at 01:40 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 15, 2020 at 11:53 AM

    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.

    -----

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 15, 2020 at 12:23 PM

    Hi SAKRIYANAIK,

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

    Regards

    Anupam

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 15, 2020 at 04:00 PM

    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.


    queue-values.jpg (69.3 kB)
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 16, 2020 at 04:48 AM

    its very simple code...with queue context

    int i=ProductID.length;

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

    it works thanks..

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.