cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping the source fields based on condition

former_member257758
Participant
0 Kudos

Hi Guru's,

I need to map one filed based on some condition.

Suppose my source value for the 'field1' is abc-123 then I need to remove all the content before '-' and then map the rest of the content i.e 123.

Is this possible using graphical mapping (pls provide the screen shot), or do I need to write UDF, If yes pls provide example.

Input for field F1      Output should be

abc-123                    123

xyz-456                    456

pqr789                      pqr789

123-ijk                       ijk

Appreciate your help

Thanks

Arun

Accepted Solutions (0)

Answers (8)

Answers (8)

Former Member
0 Kudos

u ll try below simple udf:

public String calculate1(String a, Container container) throws StreamTransformationException{

int index1 = a.indexOf("-");

if (index1 != -1 )
{

return (a.substring(index1+1));
}

else

{
return (a);

}

thanks,

Former Member
0 Kudos

Hi Arun,

for the input value pqr789    , the expected out- pqr789.

If the this is not typo - then you cant achive this requirement with substring function.

You can go for fix values , if you know what are all the input values you can expect for that particular input field.

if not fix values wont work in this case too.

if your answer is NO in both the cases - go for UDF

believe this help,

Thanks,

manigram
Active Participant
0 Kudos

Hi ,

There is an option in PI Fix Values Go to Conversions --> Fix Values.

By using this function you can acchive this easily.

Regards,

Manigandan

Bhargavakrishna
Active Contributor
0 Kudos

Hi arun,

you Dont need to write UDF, you can achieve this by using simple message mapping.

You can use sub-string function which is available under test functions in message mapping.

for ex:

it will read the character which is there at 4th position (i.e from 1 ) to till 7th character (i.e 3).

so the output will be 123.

Hope it will helpful..

Regards

Bhargava Krishna

Bhavani_Baisani
Participant
0 Kudos

Hi Arun,

use UDF like below for the field1 in mapping

Signature variables : argument       field1                  string

public String field1_Substring(String field1, Container container) throws StreamTransformationException{

String result="";

int len=field1.length();

int len1=len-3;

result=field1.substring(len1,len);

return result;

Regards,

Bhavani

Former Member
0 Kudos

Hi,

If the length of the field is fixed then we can easily achieve this using substring function. No need to go for UDF.

Find the below mapping attachment.

Regards,

Tulasiram

Bhargavakrishna
Active Contributor
0 Kudos

Hi arun,

you Dont need to write UDF, you can achieve this by using simple message mapping.

You can use sub-string function which is available under test functions in message mapping.

for ex:

it will read the character which is there at 4th position (i.e from 1 ) to till 7th character (i.e 3).

so the output will be 123.

Hope it will helpful..

Regards

Bhargava Krishna

former_member184789
Active Contributor
0 Kudos

Have this UDF:

The input is var1, execution type single values:

int w = var1.indexOf('-');

        if(w!=-1)

        {

            String Stt = var1.substring(w+1, var1.length());

            return Stt;

    }

        else

           return St;

}