[SAP PO] – UDF CONCATENATE

Hi everybody,

It’s my first post, and i want to share with all of you some problems that we can face on graphical mapping when using standard function Concat and loose the contexts, and which is the way to solve it through UDF.
Let’s suppose that we have three source fields and we want concatenate in one target field, with standard function Concat we can achieve this result:

It can be good result if we have all three fields always populate and we don’t have condition that can make change context and give us SUPPRESS result.
So we can use UDF to face this situation and solve it:

Step 1: Go to Functions TAB in Graphical Mapping and on the left give the name about function, in my case “concat” and give the Title that u prefer,
in my case “Concatenazione”, define Execution Type, in this case “All value of context”, so we can process all value about the context and don’t have suppress value.

Step 2 : Define the input variable that we will pass to java function and the result variable to store the processing under signature variables:

Step 3: In this case i did also check if the first and third input are blank or not because it will be mandatory for my requirement, if one of this is blank, mapping will fail, throw exception:
So just Copy and paste this code under:

String output = “”;
if (input.length == 0)
{
throw new RuntimeException(“Mapping Fail”);
}
else
{
for (int i = 0; i < input.length; i++)
{
output = output + input[i];
}
}

for (int i = 0; i < input2.length; i++)
 {
  output = output + "-" + input2[i];
 }

if (input3.length == 0)
        {
                        throw new RuntimeException("Mapping Fail");
        }   
                        else
        {
                                    for (int i = 0; i < input3.length; i++)
                                    {
                                         output = output + "-" + input3[i];
                                    }
}
   result.addValue(output);

Step 4: It’s the last step, just link the UDF with source and target in graphical mapping and test it:

Thanks for your reading and I’m very happy if you share your comment on this post.

Claudio Palladino

3 comments

  1. That should be done on this way if you wanted “Norway-Italy-China” (In your case it will be like “Norway-I-t-a-l-y-C-h-i-n-a”)

    String output = “”;
    if (input.length == 0){
    throw new RuntimeException(“Mapping Fail”);
    }else{
    for (int i = 0; i < input.length; i++)
    {
    output = output + input[i];
    }
    }
    output = output + "-" ;

    if (input2.length == 0){
    throw new RuntimeException(“Mapping Fail”);
    }else{
    for (int i = 0; i < input2.length; i++){
    output = output + input2[i];
    }
    }
    output = output + "-" ;

    if (input3.length == 0){
    throw new RuntimeException("Mapping Fail");
    }else{
    for (int i = 0; i < input3.length; i++){
    output = output + input3[i];
    }
    }
    result.addValue(output);

    Like

    1. Hi Goran,

      Please, test on your PI system and tell me if u have some problems.
      We accept new suggest after test and with Attachment.

      Thanks.

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.