cancel
Showing results for 
Search instead for 
Did you mean: 

UDF

former_member593220
Participant
0 Kudos

Hi Everyone,

I have a requirement for one of existing filed in PI mapping. From source PI is receiving 5 input values, using those values PI need to populate the target filed with combination input fields and which needs to implement only by using UDF.

inputs to PI (Source fields) : NAME1, NAME2, NAME3, NAME4 and COUNTRY

Target field: Displayname

Below is the mapping rule..

1) NAME1 is not blank and NAME2 is not blank and NAME3 is not blank and NAME4 is not blank then

  DisplayName should be NAME1 +_+ NAME2 +_+ COUNTRY

2) NAME1 is not blank and NAME2 is not blank and NAME3 is not blank and NAME 4 is blank

  DisplayName should be NAME1 +_+ NAME2 +_+ COUNTRY

3) NAME1 is not blank and NAME 2 is blank and NAME3 is not blank and NAME 4 is blank

  DisplayName should be NAME1 +_+ CITY1

4) NAME1 is not blank and NAME2 is not blank and NAME 3 is blank and NAME 4 is blank

  DisplayName should be NAME1 +_+ NAME2+_+ COUNTRY

5) NAME1 is not blank and NAME2 is blank and NAME 3 is blank and NAME4 is blank

  DisplayName should be NAME1 +_+ COUNTRY

6) ELSE Display Name “ERROR”

Please help me with java code to achieve this mapping rule.

Thanks in advance..!

--

With Warm Regards

Raj

Accepted Solutions (1)

Accepted Solutions (1)

sateesh_adma
Participant
0 Kudos

try the attached code 

former_member593220
Participant
0 Kudos

Hi Sateesh,

Code works fine for my requirement. Thanks a lot for your help..

--

With Warm Regards

Raj

former_member593220
Participant
0 Kudos

Hi Sateesh,

Due to there are some changes I have modified the code, and getting one issue.

Here the modifications are for example in as per our 1st condition 

NAME1 is not blank and NAME2 is not blank and NAME3 is not blank and NAME4 is not blank then

  DisplayName should be NAME1 +_+ NAME2 +_+ COUNTRY

instead of "_" PI (underscore) need to create " " (space) between the values.

And instead of COUNTRY PI need to pass the LIFNR value in place of COUNTRY

For exampla if inputs are:

NAME1 : COCA

NAME2:  COLA

NAME3:  NULL

NAME4:  NULL

LIFNR:    10005678

Then target field Display name (as per UDF) : COCA COLA 10005678 (correct output)

But am getting output as : COCA COLA - 10005678  (wrong output)

But here I am not able to find why PI is creating "-" (High-fun) between NAME2 and LIFNR.

Below is the code am using in UDF..

if(NAME1 != "" && NAME2 !="" && NAME3 !="" && NAME4 !="")

    {

    Name= NAME1+" "+NAME2+" "+LIFNR;

    }

    else if(NAME1 != "" && NAME2 !="" && NAME3 !="" && NAME4 =="")

    {

    Name= NAME1+" "+NAME2+" "+LIFNR;

    }

    else if(NAME1 != "" && NAME2 =="" && NAME3 !="" && NAME4 =="")

    {

    Name= NAME1+" "+LIFNR;

    }

    else if(NAME1 != "" && NAME2 !="" && NAME3 =="" && NAME4 =="")

    {

    Name = NAME1+" "+NAME2+" "+LIFNR;

    }

    else if (NAME1 != "" && NAME2 =="" && NAME3 =="" && NAME4 =="")

    {

    Name =NAME1+" "+LIFNR;

    }

    else DisplayName = "ERROR";

    return DisplayName;

Please help me rectifying this issue..

Thanks in advance..!

--

With Warm Regards

Raj

Answers (1)

Answers (1)

apu_das2
Active Contributor
0 Kudos

Hi Raj,

Please use following UDF .Take all inputs as a string.

String DisplayName = null;

if(!(NAME1[0].equals("") && NAME2[0].equals("") && NAME3[0].equals("") && NAME4[0].equals("")))

       DisplayName = NAME1[0] + "_" + NAME2[0] + "_" + COUNTRY[0];

else if(!(NAME1[0].equals("") && NAME2[0].equals("") && NAME3[0].equals("")) && NAME4[0].equals(""))

       DisplayName = NAME1[0] + "_" + NAME2[0] + "_" + COUNTRY[0];

else if(!(NAME1[0].equals("") && NAME3[0].equals("")) && (NAME2[0].equals("") && NAME4[0].equals("")) )

       DisplayName = NAME1[0] + "_" + COUNTRY[0];

else if(!(NAME1[0].equals("") && NAME2[0].equals("")) && (NAME3[0].equals("") && NAME4[0].equals("")) )

       DisplayName = NAME1[0] + "_" + NAME2[0] + "_" + COUNTRY[0];

else if(!(NAME1[0].equals("") && NAME2[0].equals("")) && (NAME3[0].equals("") && NAME4[0].equals("")) )

       DisplayName = NAME1[0] + "_" + COUNTRY[0];

else

       DisplayName = "ERROR";

Thanks,

Apu Das

former_member593220
Participant
0 Kudos

Hi Das,

Thanks for your reply.

I have declared all the inputs as Strings, but while testing am getting errors in all the lines saying that

"array required, but java.lang.String found"

Can you please suggest me a way to modify this code to successfully execute in PI..?

--

With Warm Regards

Raj

apu_das2
Active Contributor
0 Kudos

Hi Raj,

Can you send some screen shots what you have done so that I can have a better look.

Thanks,

Apu

former_member593220
Participant
0 Kudos

Hi Das,

I have used the below code and it works fine now.

if(NAME1 != "" && NAME2 !="" && NAME3 !="" && NAME4 !="")

    {

    Name= NAME1+" "+NAME2+" "+LIFNR;

    }

    else if(NAME1 != "" && NAME2 !="" && NAME3 !="" && NAME4 =="")

    {

    Name= NAME1+" "+NAME2+" "+LIFNR;

    }

    else if(NAME1 != "" && NAME2 =="" && NAME3 !="" && NAME4 =="")

    {

    Name= NAME1+" "+LIFNR;

    }

    else if(NAME1 != "" && NAME2 !="" && NAME3 =="" && NAME4 =="")

    {

    Name = NAME1+" "+NAME2+" "+LIFNR;

    }

    else if (NAME1 != "" && NAME2 =="" && NAME3 =="" && NAME4 =="")

    {

    Name =NAME1+" "+LIFNR;

    }

    else DisplayName = "ERROR";

    return DisplayName;

Thanks for your time..!

--

Regards

Raj