on 08-13-2009 1:30 AM
Hi folks,
i have a requirement, for a particular field that i get from sap, i need to check if it ends with - if yea then i need to put it in fron of the field and send to target.
now 1st approach would be to use the string function...ENDSWITH and CONCAT.....from the standard PI function library...
now i dont want to use this approach as the field i am talking about already goes through a lot of conditions and complex mapping to be finally populated and determined....now if i use a combination of ENDSWITH & CONCAT then i thnk il only b puttin on more over head...
instead i am trying to write a udf....something like this...
for(i=0 to a.length,i++)
if(a<i>.endsWith("-")){
String temp = a<i>.replace("-","");
Temp2= "-" concat (temp);
result.addValue(temp2);
this is the logic i want to follow, can someone lead me to an efficient coding?
Thanks,
Hank
UDF
public String getOutput(String a,Container container)
//Add this code
if(a.endsWith("-"))
{
int b = a.indexOf("-");
String c = a.substring(0,b);
return "-"+ c;
}
else
return a;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jovani,
It's simple to achieve using graphical mapping, but you said, already lot of conditions implemented in mapping. So, you will decide for your need. Anyway you can write the UDF as follows,
Create a UDF with one argument 'a'
if(a.endsWith("-"))
{
a = a.substring(0,a.length()-1);
return "-".concat(a);
}
else
return a;
If the Sting value have ends with "-", put that "-" symbol to infront of the string. Otherwise pass to target as it is.
Hope it will wok fine and simple code also.
Regards
Vijaykumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jovani,
Anyways if you want a udf you can write this:
Create a value udf with one input argument 'a' and name it as replaceminus. Add this code:
Imports: java.;*
public String replaceminus(String a,Container container)
//Add this code
if(a.endsWith("-"))
{int b = a.indexOf("-");
String c = a.substring(0,b);
return c;}
else
return a;
So if your input is abc- your output will be abc and if your input is abc then your outupt will also be abc.
Regards,
---Satish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jovani,
If you consider of performance then standard functions with endwith and replace and concat only will be much better when compared to the UDF. Even you have complex logic please go with standard functions for higher thoroughput. If you want a udf I can give that also.
Regards,
---Satish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.